summaryrefslogtreecommitdiffstats
path: root/fern.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2022-04-17 01:18:06 -0400
committersiddharth <s@ricketyspace.net>2022-04-17 01:18:06 -0400
commit3b7f9b7e47b1210ecd6ff465243cbb7e5e070228 (patch)
tree3e43f0e453cdca1252f0eb8748f72be38dbe7583 /fern.go
parentd1e84e9bebc4200179486f37cf00f17764bd911c (diff)
fern: add -run and -version flagsv0.3.0
From now, the `-run` flag needs to be explicitly given for running fern.
Diffstat (limited to 'fern.go')
-rw-r--r--fern.go32
1 files 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() {