Added version flag

master
Aaron Johnon 9 months ago
parent 510091bbfa
commit 2b00d96627

@ -8,14 +8,16 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
var Version = "development"
type Config struct { type Config struct {
ChatID string `yaml:"CHATID"` ChatID string `yaml:"CHATID"`
Token string `yaml:"TOKEN"` Token string `yaml:"TOKEN"`
@ -23,11 +25,12 @@ type Config struct {
} }
var ( var (
configFile string configFile string
chatID string chatID string
token string token string
timeout int timeout int
silent bool silent bool
versionFlag bool
) )
func init() { func init() {
@ -36,10 +39,17 @@ func init() {
pflag.StringVarP(&token, "token", "k", "", "Bot token value") pflag.StringVarP(&token, "token", "k", "", "Bot token value")
pflag.IntVarP(&timeout, "timeout", "t", 10, "Timeout value (defaults to 10)") pflag.IntVarP(&timeout, "timeout", "t", 10, "Timeout value (defaults to 10)")
pflag.BoolVarP(&silent, "silent", "s", false, "Disable notification") pflag.BoolVarP(&silent, "silent", "s", false, "Disable notification")
pflag.BoolVarP(&versionFlag, "version", "v", false, "Print version information and exit")
} }
func main() { func main() {
pflag.Parse() pflag.Parse()
if versionFlag {
fmt.Printf("tbotsend version %s\n", Version)
os.Exit(0)
}
args := pflag.Args() args := pflag.Args()
message := strings.Join(args, " ") message := strings.Join(args, " ")
@ -183,4 +193,3 @@ func printFailure(msg string) {
func printSuccess() { func printSuccess() {
fmt.Fprintf(os.Stdout, "\033[1mResult:\033[0m [\033[1;32mSUCCESS\033[0m]\n\n") fmt.Fprintf(os.Stdout, "\033[1mResult:\033[0m [\033[1;32mSUCCESS\033[0m]\n\n")
} }

Loading…
Cancel
Save