Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Framework flag shell completion #80

Conversation

MitchellBerend
Copy link
Contributor

@MitchellBerend MitchellBerend commented Nov 12, 2023

Resolves #61

This pr adds shell completion for the --framework flag. This feature should
help users with discovering framework options, prevent typos and last but not
leas, typing less.

Besides the tab completion it also replaces the string types for the
FrameworkType with a type alias Framework. The VarP function registers
a flag that always returns a valid string which then gets turned into a specific
type to make it type safe.

cc @basokant

Copy link
Contributor

@basokant basokant left a comment

Choose a reason for hiding this comment

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

Lgtm! I'm guessing u still need to run the completion command and add the completion script?

rootCmd.AddCommand(createCmd)

createCmd.Flags().StringP("name", "n", "", "Name of project to create")
createCmd.Flags().StringP("framework", "f", "", fmt.Sprintf("Framework to use. Allowed values: %s", strings.Join(allowedProjectTypes, ", ")))
createCmd.Flags().VarP(&frameworkFlag, "framework", "f", fmt.Sprintf("Framework to use. Allowed values: %s", strings.Join(frameworks.AllowedProjectTypes, ", ")))

This comment was marked as resolved.

cmd/create.go Outdated
@@ -62,16 +68,16 @@ var createCmd = &cobra.Command{
flagFramework := cmd.Flag("framework").Value.String()

if flagFramework != "" {
isValid := isValidProjectType(flagFramework, allowedProjectTypes)
isValid := isValidProjectType(flagFramework, frameworks.AllowedProjectTypes)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be removed I believe, a Var flag will automatically error if it's not in the enum!

@@ -38,7 +38,7 @@ func InitSteps(options *Options) *Steps {
StepName: "Go Project Framework",
Options: []Item{
{
Title: "Standard library",
Title: "Standard-library",

This comment was marked as resolved.

@MitchellBerend
Copy link
Contributor Author

MitchellBerend commented Nov 12, 2023

Lgtm! I'm guessing u still need to run the completion command and add the completion script?

Yes, you need to register the flag for the completion generation with a function that gets called for the option but that's a simple one line function.

https://github.com/MitchellBerend/go-blueprint/blob/7bef3e027fa9491d4c8a25ae1f40ff8124581bed/cmd/create.go#L47-L49

https://github.com/MitchellBerend/go-blueprint/blob/7bef3e027fa9491d4c8a25ae1f40ff8124581bed/cmd/frameworks/frameworkFlag.go#L42-L44

cc @basokant

@MitchellBerend MitchellBerend marked this pull request as ready for review November 12, 2023 15:37
@basokant
Copy link
Contributor

Lgtm! I'm guessing u still need to run the completion command and add the completion script?

Yes, you need to register the flag for the completion generation with a function that gets called for the option but that's a simple one line function.

https://github.com/MitchellBerend/go-blueprint/blob/7bef3e027fa9491d4c8a25ae1f40ff8124581bed/cmd/create.go#L47-L49

https://github.com/MitchellBerend/go-blueprint/blob/7bef3e027fa9491d4c8a25ae1f40ff8124581bed/cmd/frameworks/frameworkFlag.go#L42-L44

cc @basokant

This is awesome! I thought you would have to add the shell completion script that's generated from 'go-blueprint completion', but this is way better!

@MitchellBerend MitchellBerend changed the title Initial implementation for framework flag shell completion Framework flag shell completion Nov 12, 2023
Copy link
Owner

@Melkeydev Melkeydev left a comment

Choose a reason for hiding this comment

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

i think this could be out of scope for Go-blueprint because modifying dot files seems to be a little much for this CLI tool.
Personally, I wouldnt want something I installed just for spinning up Go boiler plate to touch my dot files.
I think certain users can have a poor experience with that.

@Melkeydev Melkeydev closed this Nov 13, 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.

Proposal: shell completion for --framework flag
3 participants