test: add e2e test suite and fix namespace/mention/assignee flags
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
11
cmd/alias.go
11
cmd/alias.go
@@ -22,11 +22,12 @@ var aliasCmd = &cobra.Command{
|
||||
return
|
||||
}
|
||||
if len(args) == 1 {
|
||||
if a, err := cfg.GetAlias(args[0]); err != nil {
|
||||
a, err := cfg.GetAlias(args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "alias not found:", args[0])
|
||||
} else {
|
||||
fmt.Println(a.Command)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(a.Command)
|
||||
return
|
||||
}
|
||||
if err := cfg.SetAlias(&service.Alias{Name: args[0], Command: args[1], Description: aliasDesc}); err != nil {
|
||||
@@ -42,9 +43,9 @@ var aliasDelCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if err := cfg.DeleteAlias(args[0]); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
} else {
|
||||
output.PrintAction(cmd.OutOrStdout(), "Alias deleted", args[0], false)
|
||||
os.Exit(1)
|
||||
}
|
||||
output.PrintAction(cmd.OutOrStdout(), "Alias deleted", args[0], false)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ var delCmd = &cobra.Command{
|
||||
|
||||
n, err := svc.GetByID(args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "node not found: %s", args[0])
|
||||
return
|
||||
fmt.Fprintf(os.Stderr, "node not found: %s\n", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !dForce {
|
||||
|
||||
18
cmd/root.go
18
cmd/root.go
@@ -44,22 +44,38 @@ func registerAliasCommands() {
|
||||
acmd = strings.ReplaceAll(acmd, "$me", cfg.GetUser())
|
||||
parts := strings.Fields(acmd)
|
||||
var expanded []string
|
||||
usedArgs := make([]bool, len(args))
|
||||
for _, part := range parts {
|
||||
if part == "$@" {
|
||||
expanded = append(expanded, args...)
|
||||
for i := range usedArgs {
|
||||
usedArgs[i] = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
hasCatchAll := strings.Contains(part, "$@")
|
||||
replaced := part
|
||||
if hasCatchAll {
|
||||
replaced = strings.ReplaceAll(replaced, "$@", strings.Join(args, " "))
|
||||
for i := range usedArgs {
|
||||
usedArgs[i] = true
|
||||
}
|
||||
}
|
||||
for i := len(args) - 1; i >= 0; i-- {
|
||||
placeholder := fmt.Sprintf("$%d", i+1)
|
||||
replaced = strings.ReplaceAll(replaced, placeholder, args[i])
|
||||
if strings.Contains(replaced, placeholder) {
|
||||
replaced = strings.ReplaceAll(replaced, placeholder, args[i])
|
||||
usedArgs[i] = true
|
||||
}
|
||||
}
|
||||
expanded = append(expanded, replaced)
|
||||
}
|
||||
// Forward any unconsumed args (e.g. --json flag).
|
||||
for i, arg := range args {
|
||||
if !usedArgs[i] {
|
||||
expanded = append(expanded, arg)
|
||||
}
|
||||
}
|
||||
rootCmd.SetArgs(expanded)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
|
||||
@@ -18,11 +18,12 @@ var showCmd = &cobra.Command{
|
||||
return
|
||||
}
|
||||
|
||||
if n, err := svc.GetByID(args[0]); err == nil {
|
||||
output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
||||
} else {
|
||||
n, err := svc.GetByID(args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "node not found:", args[0])
|
||||
os.Exit(1)
|
||||
}
|
||||
output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user