Skip to content

Commit

Permalink
info: improve usage
Browse files Browse the repository at this point in the history
  • Loading branch information
brmzkw committed Feb 6, 2025
1 parent c7a6b4d commit f87b264
Showing 1 changed file with 13 additions and 4 deletions.
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

0 comments on commit f87b264

Please sign in to comment.