-
Notifications
You must be signed in to change notification settings - Fork 239
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
Closed
MitchellBerend
wants to merge
8
commits into
Melkeydev:main
from
MitchellBerend:feature/framework-completion
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
772aa23
Initial implementation for framework flag shell completion
MitchellBerend 0298b97
Created separate file for framekwork flag and cleaned up original file
MitchellBerend 09fa0d7
Replaced all hardcoded framework strings to Framework constants
MitchellBerend 8e85826
Turned ProjectType string type into an actual Framework type to ensur…
MitchellBerend f520053
Removed redundant validation for framework flag
MitchellBerend d59e729
Commented out unused function
MitchellBerend 7bef3e0
Updated FrameworkMap to index Frameworks
MitchellBerend 765f369
Added some comments and removed dead code
MitchellBerend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package frameworks | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
type Framework string | ||
|
||
// These are all the current frameworks supported, if you want to add one you | ||
// can simply copy and past a line here. Do not forget to also add it into the | ||
// AllowedProjectTypes slice too! | ||
const ( | ||
Chi Framework = "chi" | ||
Gin Framework = "gin" | ||
Fiber Framework = "fiber" | ||
GorillaMux Framework = "gorilla/mux" | ||
HttpRouter Framework = "httprouter" | ||
StandardLibrary Framework = "standard-library" | ||
Echo Framework = "echo" | ||
) | ||
|
||
var AllowedProjectTypes = []string{string(Chi), string(Gin), string(Fiber), string(GorillaMux), string(HttpRouter), string(StandardLibrary), string(Echo)} | ||
|
||
// This interface is required on a type to make it useable as a flag | ||
// | ||
// type Value interface { | ||
// String() string | ||
// Set(string) error | ||
// Type() string | ||
// } | ||
func (f Framework) String() string { | ||
return string(f) | ||
} | ||
|
||
func (f *Framework) Type() string { | ||
return "Framework" | ||
} | ||
|
||
func (f *Framework) Set(value string) error { | ||
switch value { | ||
case Chi.String(), Gin.String(), Fiber.String(), GorillaMux.String(), HttpRouter.String(), StandardLibrary.String(), Echo.String(): | ||
*f = Framework(value) | ||
return nil | ||
default: | ||
return fmt.Errorf("Framework to use. Allowed values: %s", strings.Join(AllowedProjectTypes, ", ")) | ||
} | ||
} | ||
|
||
// This function returns the options that are shown to the user on shell | ||
// completions for the -f or --framework flag | ||
func FrameworkCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
return AllowedProjectTypes, cobra.ShellCompDirectiveDefault | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.