mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix: address verified review findings (cli-core-1)
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
12 files changed
+181
-21
No files matched your search
+12
-12
@@ -361,12 +361,21 @@ func builtins(root *cobra.Command) map[string]bool {
|
||||
// Execute expands aliases and executes the fresh root without printing errors.
|
||||
func Execute(ctx context.Context, deps Dependencies, args []string) error {
|
||||
root := NewRoot(deps)
|
||||
if at := commandIndex(root, args); at == len(args) || (args[at] != cobra.ShellCompRequestCmd && args[at] != cobra.ShellCompNoDescRequestCmd) {
|
||||
args = joinJSONFields(root, args)
|
||||
}
|
||||
// Broken settings or aliases must not prevent help or recovery commands.
|
||||
snapshot, loadErr := deps.Settings.Load()
|
||||
names := builtins(root)
|
||||
if loadErr == nil {
|
||||
for name, expansion := range snapshot.Preferences.Aliases {
|
||||
if aliases.Check(name, snapshot.Preferences.Aliases, names) == nil {
|
||||
root.AddCommand(&cobra.Command{Use: name, Short: fmt.Sprintf("Alias for %q", expansion), GroupID: "alias", Annotations: map[string]string{"tea.alias": "true"}, RunE: func(*cobra.Command, []string) error {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("alias must be expanded before execution"))
|
||||
}})
|
||||
}
|
||||
}
|
||||
}
|
||||
if at := commandIndex(root, args); at == len(args) || (args[at] != cobra.ShellCompRequestCmd && args[at] != cobra.ShellCompNoDescRequestCmd) {
|
||||
args = joinJSONFields(root, args)
|
||||
}
|
||||
if commandAt := commandIndex(root, args); commandAt < len(args) {
|
||||
name := args[commandAt]
|
||||
completion := name == cobra.ShellCompRequestCmd || name == cobra.ShellCompNoDescRequestCmd
|
||||
@@ -394,15 +403,6 @@ func Execute(ctx context.Context, deps Dependencies, args []string) error {
|
||||
args = completeJSONValue(args)
|
||||
}
|
||||
}
|
||||
if loadErr == nil {
|
||||
for name, expansion := range snapshot.Preferences.Aliases {
|
||||
if aliases.Check(name, snapshot.Preferences.Aliases, names) == nil {
|
||||
root.AddCommand(&cobra.Command{Use: name, Short: fmt.Sprintf("Alias for %q", expansion), GroupID: "alias", Annotations: map[string]string{"tea.alias": "true"}, RunE: func(*cobra.Command, []string) error {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("alias must be expanded before execution"))
|
||||
}})
|
||||
}
|
||||
}
|
||||
}
|
||||
root.SetArgs(args)
|
||||
err := root.ExecuteContext(ctx)
|
||||
if apiErr, ok := errors.AsType[*transport.APIError](err); ok && apiErr.Status == 401 {
|
||||
|
||||
Reference in new issue
Block a user