Skip to content

Commit

Permalink
Merge pull request #428 from PlakarKorp/jcastets/help-messages
Browse files Browse the repository at this point in the history
Jcastets/help messages
  • Loading branch information
brmzkw authored Feb 6, 2025
2 parents 9fd7c01 + f87b264 commit 224dcb9
Show file tree
Hide file tree
Showing 24 changed files with 157 additions and 13 deletions.
17 changes: 13 additions & 4 deletions cmd/plakar/plakar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -110,6 +109,18 @@ func entryPoint() int {
flag.BoolVar(&opt_quiet, "quiet", false, "no output except errors")
flag.StringVar(&opt_keyfile, "keyfile", "", "use passphrase from key file when prompted")
flag.BoolVar(&opt_agentless, "no-agent", false, "run without agent")

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [OPTIONS] COMMAND [COMMAND_OPTIONS]...\n", flag.CommandLine.Name())
fmt.Fprintf(flag.CommandLine.Output(), "\nOPTIONS:\n")
flag.PrintDefaults()

fmt.Fprintf(flag.CommandLine.Output(), "\nCOMMANDS:\n")
for _, k := range subcommands.List() {
fmt.Fprintf(flag.CommandLine.Output(), " %s\n", k)
}
fmt.Fprintf(flag.CommandLine.Output(), "\nFor more information on a command, use '%s help COMMAND'.\n", flag.CommandLine.Name())
}
flag.Parse()

ctx := appcontext.NewAppContext()
Expand Down Expand Up @@ -198,9 +209,7 @@ func entryPoint() int {

if flag.NArg() == 0 {
fmt.Fprintf(os.Stderr, "%s: a subcommand must be provided\n", filepath.Base(flag.CommandLine.Name()))
items := append(make([]string, 0, len(subcommands.List())), subcommands.List()...)
sort.Strings(items)
for _, k := range items {
for _, k := range subcommands.List() {
fmt.Fprintf(os.Stderr, " %s\n", k)
}

Expand Down
8 changes: 7 additions & 1 deletion cmd/plakar/subcommands/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ func parse_cmd_agent(ctx *appcontext.AppContext, repo *repository.Repository, ar
var opt_prometheus string

flags := flag.NewFlagSet("agent", flag.ExitOnError)
flags.StringVar(&opt_prometheus, "prometheus", "", "prometheus exporter interface")
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.StringVar(&opt_prometheus, "prometheus", "", "prometheus exporter interface, e.g. 127.0.0.1:9090")
flags.Parse(args)

return &Agent{
Expand Down
8 changes: 7 additions & 1 deletion cmd/plakar/subcommands/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ func parse_cmd_archive(ctx *appcontext.AppContext, repo *repository.Repository,
var opt_format string

flags := flag.NewFlagSet("archive", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] [SNAPSHOT[:PATH]]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.StringVar(&opt_output, "output", "", "archive pathname")
flags.BoolVar(&opt_rebase, "rebase", false, "strip pathname when pulling")
flags.StringVar(&opt_format, "format", "tarball", "archive format")
flags.StringVar(&opt_format, "format", "tarball", "archive format: tar, tarball, zip")
flags.Parse(args)

if flags.NArg() == 0 {
Expand Down
8 changes: 8 additions & 0 deletions cmd/plakar/subcommands/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ func parse_cmd_backup(ctx *appcontext.AppContext, repo *repository.Repository, a
// var opt_stdio bool

excludes := []glob.Glob{}

flags := flag.NewFlagSet("backup", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] path\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s [OPTIONS] s3://path\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.Uint64Var(&opt_concurrency, "concurrency", uint64(ctx.MaxConcurrency), "maximum number of parallel tasks")
flags.StringVar(&opt_tags, "tag", "", "tag to assign to this snapshot")
flags.StringVar(&opt_excludes, "excludes", "", "file containing a list of exclusions")
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/cat/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func parse_cmd_cat(ctx *appcontext.AppContext, repo *repository.Repository, args
var opt_highlight bool

flags := flag.NewFlagSet("cat", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] [SNAPSHOT[:PATH]]...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.BoolVar(&opt_nodecompress, "no-decompress", false, "do not try to decompress output")
flags.BoolVar(&opt_highlight, "highlight", false, "highlight output")
flags.Parse(args)
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func parse_cmd_check(ctx *appcontext.AppContext, repo *repository.Repository, ar
var opt_quiet bool

flags := flag.NewFlagSet("check", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] [SNAPSHOT[:PATH]]...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.Uint64Var(&opt_concurrency, "concurrency", uint64(ctx.MaxConcurrency), "maximum number of parallel tasks")
flags.BoolVar(&opt_noVerify, "no-verify", false, "disable signature verification")
flags.BoolVar(&opt_fastCheck, "fast", false, "enable fast checking (no checksum verification)")
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/checksum/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func parse_cmd_checksum(ctx *appcontext.AppContext, repo *repository.Repository,
var enableFastChecksum bool

flags := flag.NewFlagSet("checksum", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] [SNAPSHOT[:PATH]]...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.BoolVar(&enableFastChecksum, "fast", false, "enable fast checksum (return recorded checksum)")

flags.Parse(args)
Expand Down
4 changes: 4 additions & 0 deletions cmd/plakar/subcommands/cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package cleanup

import (
"flag"
"fmt"

"github.com/PlakarKorp/plakar/appcontext"
"github.com/PlakarKorp/plakar/cmd/plakar/subcommands"
Expand All @@ -30,6 +31,9 @@ func init() {

func parse_cmd_cleanup(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
flags := flag.NewFlagSet("cleanup", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s\n", flags.Name())
}
flags.Parse(args)

return &Cleanup{
Expand Down
9 changes: 7 additions & 2 deletions cmd/plakar/subcommands/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ func init() {

func parse_cmd_clone(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
flags := flag.NewFlagSet("clone", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] to /path/to/repository\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s [OPTIONS] to s3://bucket/path\n", flags.Name())
flags.PrintDefaults()
}

flags.Parse(args)

if flags.NArg() != 2 || flags.Arg(0) != "to" {
ctx.GetLogger().Error("usage: %s to repository", flags.Name())
return nil, fmt.Errorf("usage: %s to repository", flags.Name())
return nil, fmt.Errorf("usage: %s to <repository>. See '%s -h' or 'help %s'", flags.Name(), flags.Name(), flags.Name())
}

return &Clone{
Expand Down
7 changes: 7 additions & 0 deletions cmd/plakar/subcommands/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func parse_cmd_create(ctx *appcontext.AppContext, repo *repository.Repository, a
var opt_allowweak bool

flags := flag.NewFlagSet("create", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] /path/to/repository\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s [OPTIONS] s3://bucket/path\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.BoolVar(&opt_allowweak, "weak-passphrase", false, "allow weak passphrase to protect the repository")
flags.BoolVar(&opt_noencryption, "no-encryption", false, "disable transparent encryption")
flags.BoolVar(&opt_nocompression, "no-compression", false, "disable transparent compression")
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func init() {
func parse_cmd_diff(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
var opt_highlight bool
flags := flag.NewFlagSet("diff", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] SNAPSHOT:PATH SNAPSHOT[:PATH]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.BoolVar(&opt_highlight, "highlight", false, "highlight output")
flags.Parse(args)

Expand Down
5 changes: 5 additions & 0 deletions cmd/plakar/subcommands/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func init() {

func parse_cmd_exec(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
flags := flag.NewFlagSet("exec", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] SNAPSHOT:/path/to/executable [arg]...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}
flags.Parse(args)

if flags.NArg() == 0 {
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/help/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func init() {
func parse_cmd_help(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
var opt_style string
flags := flag.NewFlagSet("help", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
fmt.Fprint(flags.Output(), "\nTo view the man page for a specific command, run 'plakar help SUBCOMMAND'.\n")
}
flags.StringVar(&opt_style, "style", "dracula", "style to use")
flags.Parse(args)

Expand Down
17 changes: 13 additions & 4 deletions cmd/plakar/subcommands/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,22 @@ func parse_cmd_info(ctx *appcontext.AppContext, repo *repository.Repository, arg
}

flags := flag.NewFlagSet("info", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s snapshot SNAPSHOT\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s errors SNAPSHOT\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s state [STATE]...\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s packfile [PACKFILE]...\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s object [OBJECT]\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s vfs SNAPSHOT[:PATH]\n", flags.Name())
}
flags.Parse(args)

// Determine which concept to show information for based on flags.Args()[0]
switch flags.Arg(0) {
case "snapshot":
if len(flags.Args()) < 2 {
return nil, fmt.Errorf("usage: %s snapshot snapshotID", flags.Name())
return nil, fmt.Errorf("usage: %s snapshot SNAPSHOT", flags.Name())
}
return &InfoSnapshot{
RepositoryLocation: repo.Location(),
Expand All @@ -53,7 +62,7 @@ func parse_cmd_info(ctx *appcontext.AppContext, repo *repository.Repository, arg
}, nil
case "errors":
if len(flags.Args()) < 2 {
return nil, fmt.Errorf("usage: %s errors snapshotID", flags.Name())
return nil, fmt.Errorf("usage: %s errors SNAPSHOT", flags.Name())
}
return &InfoErrors{
RepositoryLocation: repo.Location(),
Expand All @@ -74,7 +83,7 @@ func parse_cmd_info(ctx *appcontext.AppContext, repo *repository.Repository, arg
}, nil
case "object":
if len(flags.Args()) < 2 {
return nil, fmt.Errorf("usage: %s object objectID", flags.Name())
return nil, fmt.Errorf("usage: %s object OBJECT", flags.Name())
}
return &InfoObject{
RepositoryLocation: repo.Location(),
Expand All @@ -83,7 +92,7 @@ func parse_cmd_info(ctx *appcontext.AppContext, repo *repository.Repository, arg
}, nil
case "vfs":
if len(flags.Args()) < 2 {
return nil, fmt.Errorf("usage: %s vfs snapshotPathname", flags.Name())
return nil, fmt.Errorf("usage: %s vfs SNAPSHOT[:PATH]", flags.Name())
}
return &InfoVFS{
RepositoryLocation: repo.Location(),
Expand Down
5 changes: 5 additions & 0 deletions cmd/plakar/subcommands/locate/locate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func parse_cmd_locate(ctx *appcontext.AppContext, repo *repository.Repository, a
var opt_snapshot string

flags := flag.NewFlagSet("locate", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] PATTERN...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}
flags.StringVar(&opt_snapshot, "snapshot", "", "snapshot to locate in")
flags.Parse(args)

Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func parse_cmd_ls(ctx *appcontext.AppContext, repo *repository.Repository, args
var opt_uuid bool

flags := flag.NewFlagSet("ls", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] [SNAPSHOT[:PATH]]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.BoolVar(&opt_uuid, "uuid", false, "display uuid instead of short ID")
flags.StringVar(&opt_tag, "tag", "", "filter by tag")
flags.BoolVar(&opt_recursive, "recursive", false, "recursive listing")
Expand Down
3 changes: 3 additions & 0 deletions cmd/plakar/subcommands/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func init() {

func parse_cmd_mount(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
flags := flag.NewFlagSet("mount", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s PATH\n", flags.Name())
}
flags.Parse(args)

if flags.NArg() != 1 {
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func parse_cmd_restore(ctx *appcontext.AppContext, repo *repository.Repository,
var opt_quiet bool

flags := flag.NewFlagSet("restore", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] [SNAPSHOT[:PATH]]...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.Uint64Var(&opt_concurrency, "concurrency", uint64(ctx.MaxConcurrency), "maximum number of parallel tasks")
flags.StringVar(&pullPath, "to", ctx.CWD, "base directory where pull will restore")
flags.BoolVar(&pullRebase, "rebase", false, "strip pathname when pulling")
Expand Down
6 changes: 6 additions & 0 deletions cmd/plakar/subcommands/rm/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func parse_cmd_rm(ctx *appcontext.AppContext, repo *repository.Repository, args
var opt_older string
var opt_tag string
flags := flag.NewFlagSet("rm", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] SNAPSHOT...\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.StringVar(&opt_tag, "tag", "", "filter by tag")
flags.StringVar(&opt_older, "older", "", "remove snapshots older than this date")
flags.Parse(args)
Expand Down
7 changes: 7 additions & 0 deletions cmd/plakar/subcommands/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package server

import (
"flag"
"fmt"

"github.com/PlakarKorp/plakar/appcontext"
"github.com/PlakarKorp/plakar/cmd/plakar/subcommands"
Expand All @@ -34,6 +35,12 @@ func parse_cmd_server(ctx *appcontext.AppContext, repo *repository.Repository, a
var opt_allowdelete bool

flags := flag.NewFlagSet("server", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.StringVar(&opt_listen, "listen", "127.0.0.1:9876", "address to listen on")
flags.BoolVar(&opt_allowdelete, "allow-delete", false, "disable delete operations")
flags.Parse(args)
Expand Down
7 changes: 7 additions & 0 deletions cmd/plakar/subcommands/stdio/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package stdio

import (
"flag"
"fmt"

"github.com/PlakarKorp/plakar/appcontext"
"github.com/PlakarKorp/plakar/cmd/plakar/subcommands"
Expand All @@ -33,6 +34,12 @@ func parse_cmd_stdio(ctx *appcontext.AppContext, repo *repository.Repository, ar
var opt_allowdelete bool

flags := flag.NewFlagSet("stdio", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS]\n", flags.Name())
fmt.Fprintf(flags.Output(), "\nOPTIONS:\n")
flags.PrintDefaults()
}

flags.BoolVar(&opt_allowdelete, "allow-delete", false, "disable delete operations")
flags.Parse(args)

Expand Down
6 changes: 5 additions & 1 deletion cmd/plakar/subcommands/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func init() {

func parse_cmd_sync(ctx *appcontext.AppContext, repo *repository.Repository, args []string) (subcommands.Subcommand, error) {
flags := flag.NewFlagSet("sync", flag.ExitOnError)
flags.Usage = func() {
fmt.Fprintf(flags.Output(), "Usage: %s [OPTIONS] SNAPSHOT to REPOSITORY\n", flags.Name())
fmt.Fprintf(flags.Output(), " %s [OPTIONS] SNAPSHOT from REPOSITORY\n", flags.Name())
flags.PrintDefaults()
}
flags.Parse(args)
return &Sync{
RepositoryLocation: repo.Location(),
Expand Down Expand Up @@ -76,7 +81,6 @@ func (cmd *Sync) Execute(ctx *appcontext.AppContext, repo *repository.Repository
peerRepositoryPath = cmd.Args[2]

default:
ctx.GetLogger().Error("usage: sync [snapshotID] to|from repository")
return 1, fmt.Errorf("usage: sync [snapshotID] to|from repository")
}

Expand Down
Loading

0 comments on commit 224dcb9

Please sign in to comment.