Skip to content

Commit

Permalink
cli: improve usagemsgs
Browse files Browse the repository at this point in the history
just a couple of changes to avoid tracebacks when someone just runs
`atomfs mount` or `atomfs mount -h` to see what the usage should be.

for both, use ArgsUsage to add the args info to the help output

for mount, check #args and run findImage before the priv check so we get
usage first

for umount update the message to include the command

Signed-off-by: Michael McCracken <[email protected]>
  • Loading branch information
mikemccracken authored Sep 26, 2024
1 parent ad93e06 commit 313b480
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 13 additions & 8 deletions cmd/atomfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import (
)

var mountCmd = cli.Command{
Name: "mount",
Usage: "mount atomfs image",
Action: doMount,
Name: "mount",
Usage: "mount atomfs image",
ArgsUsage: "ocidir:tag target",
Action: doMount,
Flags: []cli.Flag{
cli.StringFlag{
Name: "persist, upper, upperdir",
Expand Down Expand Up @@ -50,6 +51,15 @@ func findImage(ctx *cli.Context) (string, string, error) {
}

func doMount(ctx *cli.Context) error {

if len(ctx.Args()) == 0 {
return mountUsage(ctx.App.Name)
}

ocidir, tag, err := findImage(ctx)
if err != nil {
return err
}
if !amPrivileged() {
fmt.Println("Please run as root, or in a user namespace")
fmt.Println(" You could try:")
Expand All @@ -59,11 +69,6 @@ func doMount(ctx *cli.Context) error {
fmt.Println("then run from that shell")
os.Exit(1)
}
ocidir, tag, err := findImage(ctx)
if err != nil {
return err
}

target := ctx.Args()[1]
metadir := filepath.Join(target, "meta")

Expand Down
9 changes: 5 additions & 4 deletions cmd/atomfs/umount.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
)

var umountCmd = cli.Command{
Name: "umount",
Usage: "unmount atomfs image",
Action: doUmount,
Name: "umount",
Usage: "unmount atomfs image",
ArgsUsage: "mountpoint",
Action: doUmount,
}

func umountUsage(me string) error {
return fmt.Errorf("Usage: %s mountpoint", me)
return fmt.Errorf("Usage: %s umount mountpoint", me)
}

func isMountpoint(p string) bool {
Expand Down

0 comments on commit 313b480

Please sign in to comment.