feat(cli): positional audit grammar (account positional, ls alias)
This commit is contained in:
+15
-6
@@ -339,21 +339,30 @@ func runConfig(args []string, role store.Role, out, errOut io.Writer) int {
|
||||
}
|
||||
}
|
||||
|
||||
// runAudit handles `audit list [--account <name>] [--limit N]`.
|
||||
// runAudit handles `audit list [account] [--limit N]`.
|
||||
func runAudit(args []string, role store.Role, out, errOut io.Writer) int {
|
||||
if len(args) > 0 && helpRequested(args[0]) {
|
||||
printCmdUsage(out, "audit")
|
||||
return 0
|
||||
}
|
||||
if len(args) == 0 || args[0] != "list" {
|
||||
fmt.Fprintln(errOut, "usage: emcli audit list [--account <name>] [--limit N]")
|
||||
if len(args) == 0 || normalizeVerb(args[0]) != "list" {
|
||||
fmt.Fprintln(errOut, "usage: emcli audit list [account] [--limit N]")
|
||||
return 2
|
||||
}
|
||||
// Peel an optional positional account before flag parsing.
|
||||
rest := args[1:]
|
||||
var account string
|
||||
if len(rest) > 0 && !strings.HasPrefix(rest[0], "-") {
|
||||
account, rest = rest[0], rest[1:]
|
||||
}
|
||||
fs := flag.NewFlagSet("audit list", flag.ContinueOnError)
|
||||
fs.SetOutput(errOut)
|
||||
account := fs.String("account", "", "filter by account")
|
||||
limit := fs.Int("limit", 50, "max rows")
|
||||
if err := fs.Parse(args[1:]); err != nil {
|
||||
if err := fs.Parse(rest); err != nil {
|
||||
return 2
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
fmt.Fprintf(errOut, "unexpected argument %q\n", fs.Arg(0))
|
||||
return 2
|
||||
}
|
||||
st, err := openStore(role)
|
||||
@@ -362,7 +371,7 @@ func runAudit(args []string, role store.Role, out, errOut io.Writer) int {
|
||||
return 1
|
||||
}
|
||||
defer st.Close()
|
||||
if err := auditList(st, *account, *limit, out); err != nil {
|
||||
if err := auditList(st, account, *limit, out); err != nil {
|
||||
fmt.Fprintf(errOut, "audit list: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user