Adding proper command line option parsing
authorspf13 <steve.francia@gmail.com>
Fri, 19 Jul 2013 07:38:24 +0000 (00:38 -0700)
committerspf13 <steve.francia@gmail.com>
Fri, 19 Jul 2013 07:38:24 +0000 (00:38 -0700)
README.md
docs/content/doc/usage.md
main.go

index cd57ec91aee0e04dc3a1a505ac9b2f11409e7d1d..623da591ffa8dbd21d9335e3e1dc65f71826cd00 100644 (file)
--- a/README.md
+++ b/README.md
@@ -168,15 +168,17 @@ Make sure either hugo is in your path or provide a path to it.
 
     $ hugo --help
     usage: hugo [flags] []
-      -b="": hostname (and path) to the root eg. http://spf13.com/
-      -c="config.json": config file (default is path/config.json)
-      -d=false: include content marked as draft
-      -h=false: show this help
-      -k=false: analyze content and provide feedback
-      -p="": filesystem path to read files relative from
-      -w=false: watch filesystem for changes and recreate as needed
-      -s=false: a (very) simple webserver
-      -port="1313": port for webserver to run on
+      -b, --base-url="": hostname (and path) to the root eg. http://spf13.com/
+      -d, --build-drafts=false: include content marked as draft
+          --config="": config file (default is path/config.yaml|json|toml)
+      -h, --help=false: show this help
+          --port="1313": port to run web server on, default :1313
+      -S, --server=false: run a (very) simple web server
+      -s, --source="": filesystem path to read files relative from
+          --uglyurls=false: use /filename.html instead of /filename/
+      -v, --verbose=false: verbose output
+          --version=false: which version of hugo
+      -w, --watch=false: watch filesystem for changes and recreate as needed
 
 The most common use is probably to run hugo with your current 
 directory being the input directory.
@@ -192,8 +194,19 @@ immediately, tell Hugo to watch for changes. **It will
 recreate the site faster than you can tab over to 
 your browser to view the changes.**
 
-    $ hugo -p ~/mysite -w
+    $ hugo --source ~/mysite --watch
+       Watching for changes. Press ctrl+c to stop
+       15 pages created
+       0 tags created
 
+Hugo can even run a server and create your site at the same time!
+
+    $hugo --server -ws ~/mysite
+       Watching for changes. Press ctrl+c to stop
+       15 pages created
+       0 tags created
+       Web Server is available at http://localhost:1313
+       Press ctrl+c to stop
 
 # Layout
 
index 772c1039453c36fda4dfef18a2d97a98e4a4c885..5cee1ed23e6fcd67be1ec00629f72d81cdb1ec3d 100644 (file)
@@ -7,15 +7,17 @@ Make sure either hugo is in your path or provide a path to it.
 
     $ hugo --help
     usage: hugo [flags] []
-      -b="": hostname (and path) to the root eg. http://spf13.com/
-      -c="config.json": config file (default is path/config.json)
-      -d=false: include content marked as draft
-      -h=false: show this help
-      -k=false: analyze content and provide feedback
-      -p="": filesystem path to read files relative from
-      -w=false: watch filesystem for changes and recreate as needed
-      -s=false: a (very) simple webserver
-      -port="1313": port for webserver to run on
+      -b, --base-url="": hostname (and path) to the root eg. http://spf13.com/
+      -d, --build-drafts=false: include content marked as draft
+          --config="": config file (default is path/config.yaml|json|toml)
+      -h, --help=false: show this help
+          --port="1313": port to run web server on, default :1313
+      -S, --server=false: run a (very) simple web server
+      -s, --source="": filesystem path to read files relative from
+          --uglyurls=false: use /filename.html instead of /filename/
+      -v, --verbose=false: verbose output
+          --version=false: which version of hugo
+      -w, --watch=false: watch filesystem for changes and recreate as needed
 
 ## Common Usage Example:
 
@@ -35,14 +37,14 @@ immediately, tell Hugo to watch for changes.
 recreate the site faster than you can tab over to 
 your browser to view the changes.**
 
-    $ hugo -p ~/mysite -w
+    $ hugo --source ~/mysite --watch
        Watching for changes. Press ctrl+c to stop
        15 pages created
        0 tags created
 
 Hugo can even run a server and create your site at the same time!
 
-    $hugo -p ~/mysite -w -s
+    $hugo --server -ws ~/mysite
        Watching for changes. Press ctrl+c to stop
        15 pages created
        0 tags created
diff --git a/main.go b/main.go
index ddac8f02eff82a9ea5d426264a3ce333037e2f98..83239c2fa6a1c7334003625450bff2c575496880 100644 (file)
--- a/main.go
+++ b/main.go
@@ -14,9 +14,9 @@
 package main
 
 import (
-       "flag"
        "fmt"
        "github.com/howeyc/fsnotify"
+       flag "github.com/ogier/pflag"
        "github.com/spf13/hugo/hugolib"
        "net/http"
        "os"
@@ -27,17 +27,17 @@ import (
 )
 
 var (
-       baseUrl    = flag.String("b", "", "hostname (and path) to the root eg. http://spf13.com/")
-       cfgfile    = flag.String("c", "", "config file (default is path/config.yaml|json|toml)")
-       checkMode  = flag.Bool("k", false, "analyze content and provide feedback")
-       draft      = flag.Bool("d", false, "include content marked as draft")
-       help       = flag.Bool("h", false, "show this help")
-       path       = flag.String("p", "", "filesystem path to read files relative from")
-       verbose    = flag.Bool("v", false, "verbose output")
+       baseUrl    = flag.StringP("base-url", "b", "", "hostname (and path) to the root eg. http://spf13.com/")
+       cfgfile    = flag.String("config", "", "config file (default is path/config.yaml|json|toml)")
+       checkMode  = flag.Bool("check", false, "analyze content and provide feedback")
+       draft      = flag.BoolP("build-drafts", "d", false, "include content marked as draft")
+       help       = flag.BoolP("help", "h", false, "show this help")
+       path       = flag.StringP("source", "s", "", "filesystem path to read files relative from")
+       verbose    = flag.BoolP("verbose", "v", false, "verbose output")
        version    = flag.Bool("version", false, "which version of hugo")
-       cpuprofile = flag.Int("cpuprofile", 0, "Number of times to create the site and profile it")
-       watchMode  = flag.Bool("w", false, "watch filesystem for changes and recreate as needed")
-       server     = flag.Bool("s", false, "run a (very) simple web server")
+       cpuprofile = flag.Int("profile", 0, "Number of times to create the site and profile it")
+       watchMode  = flag.BoolP("watch", "w", false, "watch filesystem for changes and recreate as needed")
+       server     = flag.BoolP("server", "S", false, "run a (very) simple web server")
        port       = flag.String("port", "1313", "port to run web server on, default :1313")
        uglyUrls   = flag.Bool("uglyurls", false, "use /filename.html instead of /filename/ ")
 )
@@ -45,7 +45,7 @@ var (
 func usage() {
        PrintErr("usage: hugo [flags]", "")
        flag.PrintDefaults()
-       os.Exit(2)
+       os.Exit(0)
 }
 
 func main() {
@@ -90,7 +90,7 @@ func main() {
        if *checkMode {
                site := hugolib.NewSite(config)
                site.Analyze()
-               os.Exit(2)
+               os.Exit(0)
        }
 
        if *watchMode {