diff --git a/shell/shell.go b/shell/shell.go index fcbf3bd..65945b7 100644 --- a/shell/shell.go +++ b/shell/shell.go @@ -398,17 +398,17 @@ func execute() { if matchLiteral(cmdStart, cmdEnd, "free") { // free a previously allocated 4KB page - if !mem.PFAReady() { - terminal.Print("free: pfa not ready\n") - return - } - a1s, a1e, ok := nextArg(cmdEnd, end) if !ok { terminal.Print("Usage: free \n") return } + if !mem.PFAReady() { + terminal.Print("free: pfa not ready\n") + return + } + addr, ok := parseHex64(a1s, a1e) if !ok { terminal.Print("free: invalid hex address\n") @@ -618,6 +618,9 @@ func execute() { } return } + + terminal.Print("Usage: disk [text]\n") + return } if matchLiteral(cmdStart, cmdEnd, "fatinit") { diff --git a/shell/shell_test.go b/shell/shell_test.go index 458a29e..342211e 100644 --- a/shell/shell_test.go +++ b/shell/shell_test.go @@ -958,6 +958,47 @@ func TestExecuteAgentCommandSuccessPaths(t *testing.T) { }) } +func TestStandardizedUsageMessages(t *testing.T) { + tests := []struct { + name string + input string + want string + }{ + {"mem missing args", "mem", "Usage: mem [len]\n"}, + {"free missing args", "free", "Usage: free \n"}, + {"write missing args", "write", "Usage: write \n"}, + {"cat missing args", "cat", "Usage: cat \n"}, + {"rm missing args", "rm", "Usage: rm \n"}, + {"stat missing args", "stat", "Usage: stat \n"}, + {"disk missing args", "disk", "Usage: disk [text]\n"}, + {"disk invalid subcommand", "disk foo", "Usage: disk [text]\n"}, + {"fatcreate missing args", "fatcreate", "Usage: fatcreate \n"}, + {"fatread missing args", "fatread", "Usage: fatread \n"}, + {"layout invalid arg", "layout fr", "Usage: layout [us|it]\n"}, + {"run missing args", "run", "Usage: run \n"}, + {"agent missing args", "agent", "Usage: agent [arg]\n"}, + {"agent show missing args", "agent show", "Usage: agent show \n"}, + {"agent show invalid arg", "agent show invalid", "Usage: agent show \n"}, + {"agent read missing args", "agent read", "Usage: agent read \n"}, + {"agent delete missing args", "agent delete", "Usage: agent delete \n"}, + {"agent stat missing args", "agent stat", "Usage: agent stat \n"}, + {"agent transport missing args", "agent transport", "Usage: agent transport ping\n"}, + {"agent transport invalid subcmd", "agent transport pong", "Usage: agent transport ping\n"}, + } + + terminal.Init() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + terminal.ResetOutputForTesting() + setLineBuf(tt.input) + execute() + if got := terminal.OutputForTesting(); got != tt.want { + t.Fatalf("execute(%q) = %q, want %q", tt.input, got, tt.want) + } + }) + } +} + func TestExecute_BuiltinCommands(t *testing.T) { terminal.Init() fs.Init()