Skip to content

Conversation

aohoyd
Copy link

@aohoyd aohoyd commented Aug 30, 2022

Completions were rewritten to make it possible to have completions for all shells.

  • cmd/switcher/switcher.go was split into subcommands
  • new subcommand switch completion was introduced in cmd/switcher/completion.go
  • new subcommands list-contexts, delete-context, unset-context and current-context were implemented to make shell script as small as possible
  • flags -u|-d|-c were moved from shell into binary

Note: fish shell has built-in command switch so kubeswitch was used for fish

Fixes #42, fixes #46

@danielfoehrKn
Copy link
Owner

Thank you! Will take a look.
Could you also resolve the merge conflicts?

@aohoyd
Copy link
Author

aohoyd commented Aug 31, 2022

Could you also resolve the merge conflicts?

Fixed

@aohoyd
Copy link
Author

aohoyd commented Aug 31, 2022

@danielfoehrKn What do you think about embedding? There will be only one binary which would produce needed shell functions to source them. Final flow be like:

source <(switcher init bash —enable-completion)  # here switcher init outputs function switch() from hack/switch/switch.sh with required completions
switch …

Copy link
Owner

@danielfoehrKn danielfoehrKn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am having some questions before I'll try it out. In general, I like the refactoring aspects of it (it is overdue)

Comment on lines +30 to +31
RESPONSE="$($EXECUTABLE_PATH "${opts[@]}")"
if [ $? -ne 0 -o -z "$RESPONSE" ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have to check if all commands still work. But if it does it is a really nice refactoring

@danielfoehrKn
Copy link
Owner

What do you think about embedding?

I am not quite sure how that is different from your current approach . You could still use the switcher binary to generate the bash|fish|zsh completions and source them. Maybe I am misunderstanding something.

@aohoyd
Copy link
Author

aohoyd commented Aug 31, 2022

I am not quite sure how that is different from your current approach

Now kubeswitch contains binary switcher, switch.sh script and switch.fish script. So to completely activate switch with full completions support users should execute

source switch.sh
source <(switch completion bash)

My idea is to generate internals of switch.sh script by init subcommand. So the script above would be

source <(switcher init bash)

I mean scripts switch.sh and switch.fish can be also embedded into binary. Final distribution would contain only one binary without additional scripts

Copy link
Author

@aohoyd aohoyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to implement several more completion points


return ns.SwitchNamespace(getKubeconfigPathFromFlag(), stateDirectory, noIndex)
},
SilenceErrors: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implement ValidArgs function for autocompletion

reportNewContext(kc)
return err
},
SilenceUsage: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implement ValidArgs function for autocompletion

return err
}
return delete_context.DeleteContext(ctxName)
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implement ValidArgs function for autocompletion


return alias.RemoveAlias(args[0], stateDirectory)
},
SilenceErrors: true,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implement ValidArgs function for autocompletion

@sjentzsch
Copy link

@avlllo any chance you can continue this great work? 🙏

@danielfoehrKn danielfoehrKn merged commit 7ca69ac into danielfoehrKn:master Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"switch completion" command does not work support fish shell?
3 participants