From 3b7f9b7e47b1210ecd6ff465243cbb7e5e070228 Mon Sep 17 00:00:00 2001 From: siddharth Date: Sun, 17 Apr 2022 01:18:06 -0400 Subject: fern: add -run and -version flags From now, the `-run` flag needs to be explicitly given for running fern. --- fern.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/fern.go b/fern.go index 8b2b1ac..70e79fb 100644 --- a/fern.go +++ b/fern.go @@ -33,13 +33,17 @@ // You may download an example config file for fern from // https://ricketyspace.net/fern/fern.json // -// fern does not take any arguments, to run it just do: +// Run fern with: // -// $ fern +// $ fern -run // +// To print fern's version, do: +// +// $ fern -version package main import ( + "flag" "fmt" "os" @@ -48,9 +52,14 @@ import ( "ricketyspace.net/fern/state" ) +const version = "0.3.0" + var fConf *config.FernConfig var pState *state.ProcessState +var vFlag *bool +var rFlag *bool + func init() { var err error @@ -70,6 +79,25 @@ func init() { fmt.Printf("Error: %v\n", err.Error()) os.Exit(1) } + + // Parse args. + vFlag = flag.Bool("version", false, "Print version") + rFlag = flag.Bool("run", false, "Run fern") + flag.Parse() + + if *vFlag { + fmt.Printf("%s\n", version) + os.Exit(0) + } + if !*rFlag { + printUsage(2) + } +} + +func printUsage(exit int) { + fmt.Printf("fern [ -run | -version ]\n") + flag.PrintDefaults() + os.Exit(exit) } func main() { -- cgit v1.2.3