]> Cypherpunks.ru repositories - goredo.git/commitdiff
Separate usage help for each command
authorSergey Matveev <stargrave@stargrave.org>
Mon, 15 Feb 2021 11:52:14 +0000 (14:52 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 15 Feb 2021 11:52:14 +0000 (14:52 +0300)
main.go
usage.go

diff --git a/main.go b/main.go
index 4de78be52fa786830cfbb92862c1c495cd59140a..ee5bf041f5f608dbc70a79e0d1c8c56b31223064 100644 (file)
--- a/main.go
+++ b/main.go
@@ -29,6 +29,7 @@ import (
        "os"
        "path"
        "path/filepath"
        "os"
        "path"
        "path/filepath"
+       "runtime"
        "strconv"
 
        "go.cypherpunks.ru/recfile"
        "strconv"
 
        "go.cypherpunks.ru/recfile"
@@ -63,14 +64,14 @@ func main() {
        warranty := flag.Bool("warranty", false, "print warranty information")
        symlinks := flag.Bool("symlinks", false, "create necessary symlinks in current directory")
 
        warranty := flag.Bool("warranty", false, "print warranty information")
        symlinks := flag.Bool("symlinks", false, "create necessary symlinks in current directory")
 
-       flag.Usage = usage
+       flag.Usage = func() { usage(os.Args[0]) }
        flag.Parse()
        if *warranty {
                fmt.Println(Warranty)
                return
        }
        if *version {
        flag.Parse()
        if *warranty {
                fmt.Println(Warranty)
                return
        }
        if *version {
-               fmt.Println(versionGet())
+               fmt.Println("goredo", Version, "built with", runtime.Version())
                return
        }
        if *symlinks {
                return
        }
        if *symlinks {
index a8bb28b8191849c4289539b7f7cab38351eebbcb..52a27685dabc574f4470b61d132e44f0866c215e 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -21,13 +21,13 @@ import (
        "flag"
        "fmt"
        "os"
        "flag"
        "fmt"
        "os"
-       "runtime"
-       "strings"
 )
 
 const (
        Version  = "1.3.0"
 )
 
 const (
        Version  = "1.3.0"
-       Warranty = `This program is free software: you can redistribute it and/or modify
+       Warranty = `Copyright (C) 2020-2021 Sergey Matveev
+
+This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, version 3 of the License.
 
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, version 3 of the License.
 
@@ -40,51 +40,60 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.`
 )
 
 along with this program.  If not, see <http://www.gnu.org/licenses/>.`
 )
 
-func versionGet() string {
-       return strings.Join([]string{
-               "goredo", Version, "built with", runtime.Version(),
-       }, " ")
-}
+func usage(cmd string) {
+       var d string
+       switch cmd {
+       case "redo":
+               d = `Usage: redo [options] [target ...]
+
+Forcefully and *sequentially* build specified targets.`
+       case "redo-ifchange":
+               d = `Usage: redo-ifchange target [...]
+
+Build specified targets in parallel, if they are changed.
+Record them as dependencies for current target.`
+       case "redo-ifcreate":
+               d = `Usage: redo-ifcreate target [...]
+
+Record ifcreate dependency for current target. Unusable outside .do.`
+       case "redo-always":
+               d = `Usage: redo-always
+
+Always build current target. Unusable outside .do.`
+       case "redo-cleanup":
+               d = `Usage: redo-cleanup [-dry-run] {full,log,tmp} [...]
+
+Remove either all goredo's related temporary files, or kept stderr
+logs, or everything (including .redo directories) related.`
+       case "redo-log":
+               d = `Usage: redo-log target [ | tai64nlocal ]
+
+Display kept target's stderr with TAI64N timestamped lines. Only the
+last build is kept. You must enable stderr keeping with either -logs,
+or REDO_LOGS=1.`
+       case "redo-dot":
+               d = `Usage: redo-dot target [...]
+
+Write dependency DOT graph to stdout.`
+       case "redo-stamp":
+               d = `Usage: redo-stamp < [$3]
+
+Record stamp dependency for current target. Unusable outside .do.
+Stamp dependency does not play any role, as all targets are hashed
+anyway.`
+       case "redo-whichdo":
+               d = `Usage: redo-whichdo target
+
+Display .do search paths for specified target. Exits successfully
+if the last .do in output if the found existing one.`
+       default:
+               d = `Usage: goredo -symlinks
 
 
-func usage() {
-       fmt.Fprintf(os.Stderr, versionGet()+`
-Copyright (C) 2020-2021 Sergey Matveev
-License GPLv3: GNU GPL version 3 <http://gnu.org/licenses/gpl.html>
-This is free software: you are free to change and redistribute it.
-There is NO WARRANTY, to the extent permitted by law.
-
-redo, redo-{always,cleanup,dot,ifchange,ifcreate,log,stamp,whichdo} must
-be linked to goredo executable. It determines the command by its own name.
-You can create them by running: goredo -symlinks.
-
-* redo [options] [target ...]
-  forcefully and *sequentially* build specified targets
-* redo-always
-  always build current target. Unusable outside .do
-* redo-cleanup [-dry-run] {full,log,tmp} [...]
-  remove either all goredo's related temporary files, or kept stderr
-  logs, or everything (including .redo directories) related
-* redo-dot target [...]
-  write dependency DOT graph to stdout
-* redo-ifchange target [...]
-  build specified targets in parallel, if they are changed. Record them
-  as dependencies for current target
-* redo-ifcreate target [...]
-  record ifcreate dependency for current target. Unusable outside .do
-* redo-log target [ | tai64nlocal ]
-  display kept target's stderr with TAI64N timestamped lines. Only the
-  last build is kept. You must enable stderr keeping with either -logs,
-  or REDO_LOGS=1
-* redo-stamp < [$3]
-  record stamp dependency for current target. Unusable outside .do.
-  Stamp dependency does not play any role, as all targets are hashed
-  anyway
-* redo-whichdo target
-  display .do search paths for specified target. Exits successfully
-  if the last .do in output if the found existing one
-
-Options:
-`)
+goredo expects to be called through the symbolic link to it.
+Available commands: redo, redo-always, redo-cleanup, redo-dot,
+redo-ifchange, redo-ifcreate, redo-log, redo-stamp, redo-whichdo.`
+       }
+       fmt.Fprintf(os.Stderr, "%s\n\nOptions:\n", d)
        flag.PrintDefaults()
        fmt.Fprintln(os.Stderr, `
 Additional environment variables:
        flag.PrintDefaults()
        fmt.Fprintln(os.Stderr, `
 Additional environment variables: