Skip to content

Commit

Permalink
update cli interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mjdubell committed Feb 1, 2020
1 parent f9315a1 commit 9ee1691
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
57 changes: 57 additions & 0 deletions args.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"flag"
"fmt"
"os"
)

type cliOptions struct {
telegram bool
discord bool
slack bool
version bool
stdin bool
message string
}

func processArgs() cliOptions {

opts := cliOptions{}
flag.BoolVar(&opts.telegram, "telegram", false, "Send via telegram")
flag.BoolVar(&opts.telegram, "t", false, "Send via telegram")
flag.BoolVar(&opts.slack, "slack", false, "Send via slack")
flag.BoolVar(&opts.slack, "s", false, "Send via slack")
flag.BoolVar(&opts.version, "version", false, "Show version number")
flag.BoolVar(&opts.version, "v", false, "Show version number")
flag.BoolVar(&opts.stdin, "stdin", false, "Take input from stdin")
flag.BoolVar(&opts.stdin, "si", false, "Take input from stdin")
flag.StringVar(&opts.message, "message", "", "The message you want to send")
flag.StringVar(&opts.message, "m", "", "The message you want to send")
flag.Parse()

return opts

}

func init() {
flag.Usage = func() {
h := "\nSend data through chat channels. Made by @dubs3c.\n\n"

h += "Usage:\n"
h += " emissary [channel] [message]\n\n"

h += "Options:\n"
h += " -s, --slack Send via Slack\n"
h += " -t, --telegram Send via Telegram\n"
h += " -si, --stdin Get message from stdin\n"
h += " -m, --message Message to send\n"
h += " -v, --version Show version\n"

h += "\nExamples:\n"
h += " emissary -telegram --message \"Hello telegram\"\n"
h += " cat domins.txt | emissary --slack --stdin \n\n"

fmt.Fprintf(os.Stderr, h)
}
}
21 changes: 2 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import (
"gopkg.in/ini.v1"
)

type cliOptions struct {
telegram bool
discord bool
slack bool
version bool
stdin bool
message string
}

func checkResponse(httpResponse *http.Response, err error) {
if httpResponse.StatusCode > 201 {
body, respErr := ioutil.ReadAll(httpResponse.Body)
Expand All @@ -40,18 +31,10 @@ func checkResponse(httpResponse *http.Response, err error) {
}

func main() {
opts := cliOptions{}
flag.BoolVar(&opts.telegram, "telegram", false, "Send via telegram")
flag.BoolVar(&opts.discord, "discord", false, "Send via discord")
flag.BoolVar(&opts.slack, "slack", false, "Send via slack")
flag.BoolVar(&opts.version, "v", false, "Show version number")
flag.BoolVar(&opts.version, "version", false, "Show version number")
flag.BoolVar(&opts.stdin, "stdin", false, "Take input from stdin")
flag.StringVar(&opts.message, "message", "", "The message you want to send")
flag.Parse()
opts := processArgs()

if opts.version {
fmt.Printf("Emissary version: %s\n", "1.0")
fmt.Printf("Emissary version: %s\n", VERSION)
os.Exit(0)
}
if len(os.Args) <= 1 {
Expand Down

0 comments on commit 9ee1691

Please sign in to comment.