Skip to content

Commit c1dca3c

Browse files
committed
Add support for custom configuration file (#12)
1 parent 0dabd4e commit c1dca3c

File tree

4 files changed

+39
-115
lines changed

4 files changed

+39
-115
lines changed

app/phabulous.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,46 @@ package app
22

33
import (
44
"github.com/Sirupsen/logrus"
5+
"github.com/codegangsta/cli"
56
"github.com/etcinit/phabulous/app/bot"
6-
"github.com/etcinit/phabulous/app/workbench"
77
"github.com/jacobstr/confer"
88
"github.com/nlopes/slack"
99
)
1010

1111
// Phabulous is the root node of the DI graph
1212
type Phabulous struct {
13-
Config *confer.Config `inject:""`
14-
Engine *EngineService `inject:""`
15-
Serve *ServeService `inject:""`
16-
Slacker *bot.SlackService `inject:""`
17-
SlackWorkbench *workbench.SlackWorkbenchService `inject:""`
18-
Logger *logrus.Logger `inject:""`
13+
Config *confer.Config `inject:""`
14+
Engine *EngineService `inject:""`
15+
Serve *ServeService `inject:""`
16+
Slacker *bot.SlackService `inject:""`
17+
Logger *logrus.Logger `inject:""`
1918
}
2019

2120
// Boot the upper part of the application.
22-
func (p *Phabulous) Boot() {
23-
p.Logger.Debugln("Booting upper layer")
21+
func (p *Phabulous) Boot(c *cli.Context) {
22+
if c.GlobalString("config") != "" {
23+
err := p.Config.ReadPaths(c.GlobalString("config"))
24+
25+
if err != nil {
26+
p.Logger.Panic(err)
27+
}
28+
29+
p.Logger.Infoln(
30+
"Loaded alternate configuration file from: " +
31+
c.GlobalString("config") + ".",
32+
)
33+
}
34+
35+
if p.Config.GetBool("server.debug") {
36+
p.Logger.Level = logrus.DebugLevel
37+
p.Logger.Debugln("Logger is debug level.")
38+
} else {
39+
p.Logger.Level = logrus.WarnLevel
40+
}
2441

2542
p.Slacker.Slack = slack.New(
2643
p.Config.GetString("slack.token"),
2744
)
45+
46+
p.Logger.Debugln("Booted upper layer.")
2847
}

app/serve.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ type ServeService struct {
1515
Config *confer.Config `inject:""`
1616
Logger *logrus.Logger `inject:""`
1717
Slacker *bot.SlackService `inject:""`
18+
App *Phabulous `inject:""`
1819
}
1920

2021
// Run starts up the HTTP server
2122
func (s *ServeService) Run(c *cli.Context) {
23+
// Boot the upper layers of the app.
24+
s.App.Boot(c)
25+
2226
s.Logger.Infoln("Starting up the server... (a.k.a. coffee time)")
2327

2428
engine := s.Engine.New()

app/workbench/slack.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

cmd/phabulous/phabulous.go

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ func main() {
2626
// Create the logger.
2727
logger := logrus.New()
2828

29-
if config.GetBool("server.debug") {
30-
logger.Level = logrus.DebugLevel
31-
} else {
32-
logger.Level = logrus.WarnLevel
33-
}
34-
3529
// Next, we setup the dependency graph
3630
// In this example, the graph won't have many nodes, but on more complex
3731
// applications it becomes more useful.
@@ -47,9 +41,6 @@ func main() {
4741
os.Exit(1)
4842
}
4943

50-
// Boot the upper layers of the app.
51-
phabulous.Boot()
52-
5344
// Setup the command line application
5445
app := cli.NewApp()
5546
app.Name = "phabulous"
@@ -65,38 +56,20 @@ func main() {
6556
fmt.Println("Usage: phabulous [global options] command [command options] [arguments...]")
6657
}
6758

59+
app.Flags = []cli.Flag{
60+
cli.StringFlag{
61+
Name: "config",
62+
Usage: "Provide an alternative configuration file",
63+
},
64+
}
65+
6866
app.Commands = []cli.Command{
6967
{
7068
Name: "serve",
7169
Aliases: []string{"s", "server", "listen"},
7270
Usage: "Start the API server",
7371
Action: phabulous.Serve.Run,
7472
},
75-
{
76-
Name: "slack",
77-
Subcommands: []cli.Command{
78-
{
79-
Name: "test",
80-
Usage: "Test that the slackbot works",
81-
Action: phabulous.SlackWorkbench.SendTestMessage,
82-
},
83-
{
84-
Name: "resolve.commit",
85-
Usage: "Test that that a commit can correctly be resolved into a channel",
86-
Action: phabulous.SlackWorkbench.ResolveCommitChannel,
87-
},
88-
{
89-
Name: "resolve.task",
90-
Usage: "Test that that a task can correctly be resolved into a channel",
91-
Action: phabulous.SlackWorkbench.ResolveTaskChannel,
92-
},
93-
{
94-
Name: "resolve.revision",
95-
Usage: "Test that that a revision can correctly be resolved into a channel",
96-
Action: phabulous.SlackWorkbench.ResolveRevisionChannel,
97-
},
98-
},
99-
},
10073
}
10174

10275
// Begin

0 commit comments

Comments
 (0)