Skip to content

Commit

Permalink
add token opt to skip config
Browse files Browse the repository at this point in the history
  • Loading branch information
bcicen committed Nov 14, 2018
1 parent f4e8543 commit 1783046
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func main() {
Name: "tee, t",
Usage: "Print stdin to screen before posting",
},
cli.StringFlag{
Name: "token",
Usage: "Optional Slack token to use, ignoring config file",
},
cli.StringFlag{
Name: "username, u",
Usage: "Stream messages as given bot user. Defaults to auth user",
Expand All @@ -138,26 +142,27 @@ func main() {
}

app.Action = func(c *cli.Context) {
var config *Config

if c.Bool("configure") {
configureOA()
os.Exit(0)
}

configPath, exists := getConfigPath()
if !exists {
exitErr(fmt.Errorf("missing config file at %s\nuse --configure to create", configPath))
if c.String("token") != "" {
config = &Config{
Teams: map[string]string{
"default": c.String("token"),
},
DefaultTeam: "default",
}
} else {
configPath, exists := getConfigPath()
if !exists {
exitErr(fmt.Errorf("missing config file at %s\nuse --configure to create", configPath))
}
config = ReadConfig(configPath)
}
config := ReadConfig(configPath)

team, channel, err := config.parseChannelOpt(c.String("channel"))
failOnError(err)

noop = c.Bool("noop")
username := c.String("username")
iconEmoji := c.String("iconemoji")
fileName := c.String("filename")
fileType := c.String("filetype")
fileComment := c.String("comment")

if c.Bool("list") {
for teamName, token := range config.Teams {
Expand All @@ -175,6 +180,16 @@ func main() {
os.Exit(0)
}

team, channel, err := config.parseChannelOpt(c.String("channel"))
failOnError(err)

noop = c.Bool("noop")
username := c.String("username")
iconEmoji := c.String("iconemoji")
fileName := c.String("filename")
fileType := c.String("filetype")
fileComment := c.String("comment")

token := config.Teams[team]
if token == "" {
exitErr(fmt.Errorf("no such team: %s", team))
Expand Down

0 comments on commit 1783046

Please sign in to comment.