Skip to content

Commit

Permalink
Add support for custom configuration file (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
etcinit committed Dec 7, 2015
1 parent 0dabd4e commit c1dca3c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 115 deletions.
37 changes: 28 additions & 9 deletions app/phabulous.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,46 @@ package app

import (
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/etcinit/phabulous/app/bot"
"github.com/etcinit/phabulous/app/workbench"
"github.com/jacobstr/confer"
"github.com/nlopes/slack"
)

// Phabulous is the root node of the DI graph
type Phabulous struct {
Config *confer.Config `inject:""`
Engine *EngineService `inject:""`
Serve *ServeService `inject:""`
Slacker *bot.SlackService `inject:""`
SlackWorkbench *workbench.SlackWorkbenchService `inject:""`
Logger *logrus.Logger `inject:""`
Config *confer.Config `inject:""`
Engine *EngineService `inject:""`
Serve *ServeService `inject:""`
Slacker *bot.SlackService `inject:""`
Logger *logrus.Logger `inject:""`
}

// Boot the upper part of the application.
func (p *Phabulous) Boot() {
p.Logger.Debugln("Booting upper layer")
func (p *Phabulous) Boot(c *cli.Context) {
if c.GlobalString("config") != "" {
err := p.Config.ReadPaths(c.GlobalString("config"))

if err != nil {
p.Logger.Panic(err)
}

p.Logger.Infoln(
"Loaded alternate configuration file from: " +
c.GlobalString("config") + ".",
)
}

if p.Config.GetBool("server.debug") {
p.Logger.Level = logrus.DebugLevel
p.Logger.Debugln("Logger is debug level.")
} else {
p.Logger.Level = logrus.WarnLevel
}

p.Slacker.Slack = slack.New(
p.Config.GetString("slack.token"),
)

p.Logger.Debugln("Booted upper layer.")
}
4 changes: 4 additions & 0 deletions app/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ type ServeService struct {
Config *confer.Config `inject:""`
Logger *logrus.Logger `inject:""`
Slacker *bot.SlackService `inject:""`
App *Phabulous `inject:""`
}

// Run starts up the HTTP server
func (s *ServeService) Run(c *cli.Context) {
// Boot the upper layers of the app.
s.App.Boot(c)

s.Logger.Infoln("Starting up the server... (a.k.a. coffee time)")

engine := s.Engine.New()
Expand Down
72 changes: 0 additions & 72 deletions app/workbench/slack.go

This file was deleted.

41 changes: 7 additions & 34 deletions cmd/phabulous/phabulous.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ func main() {
// Create the logger.
logger := logrus.New()

if config.GetBool("server.debug") {
logger.Level = logrus.DebugLevel
} else {
logger.Level = logrus.WarnLevel
}

// Next, we setup the dependency graph
// In this example, the graph won't have many nodes, but on more complex
// applications it becomes more useful.
Expand All @@ -47,9 +41,6 @@ func main() {
os.Exit(1)
}

// Boot the upper layers of the app.
phabulous.Boot()

// Setup the command line application
app := cli.NewApp()
app.Name = "phabulous"
Expand All @@ -65,38 +56,20 @@ func main() {
fmt.Println("Usage: phabulous [global options] command [command options] [arguments...]")
}

app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config",
Usage: "Provide an alternative configuration file",
},
}

app.Commands = []cli.Command{
{
Name: "serve",
Aliases: []string{"s", "server", "listen"},
Usage: "Start the API server",
Action: phabulous.Serve.Run,
},
{
Name: "slack",
Subcommands: []cli.Command{
{
Name: "test",
Usage: "Test that the slackbot works",
Action: phabulous.SlackWorkbench.SendTestMessage,
},
{
Name: "resolve.commit",
Usage: "Test that that a commit can correctly be resolved into a channel",
Action: phabulous.SlackWorkbench.ResolveCommitChannel,
},
{
Name: "resolve.task",
Usage: "Test that that a task can correctly be resolved into a channel",
Action: phabulous.SlackWorkbench.ResolveTaskChannel,
},
{
Name: "resolve.revision",
Usage: "Test that that a revision can correctly be resolved into a channel",
Action: phabulous.SlackWorkbench.ResolveRevisionChannel,
},
},
},
}

// Begin
Expand Down

0 comments on commit c1dca3c

Please sign in to comment.