Skip to content

Commit

Permalink
Deprecate --show in favor of --shell
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother committed Jan 10, 2022
1 parent 2e9ab9c commit d7f2514
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
26 changes: 17 additions & 9 deletions commands/inits/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// define a variable outside with the correct scope to assign the flag to work
// with.
var includeAliases bool
var outputScript bool
var legacyShow bool
var wrapGit bool
var shellType string

Expand All @@ -26,12 +26,18 @@ Outputs the bash/zsh/fish initialization script for scmpuff.
This should probably be evaluated in your shell startup.
`,
Run: func(cmd *cobra.Command, args []string) {
if outputScript {
// If someone's using the old -s/--show flag, opt-in to the newer --shell=sh option
if legacyShow {
shellType = "sh"
}
if shellType != "" {
printScript()
} else {
fmt.Println(helpString())
}
},
// Watch out for accidental args caused by NoOptDefVal (https://github.com/spf13/cobra/issues/866)
Args: cobra.NoArgs,
}

// --aliases
Expand All @@ -41,12 +47,13 @@ This should probably be evaluated in your shell startup.
"Include short aliases for convenience",
)

// --show
InitCmd.Flags().BoolVarP(
&outputScript,
"show", "s", false,
// --show (deprecated in favor of --shell)
InitCmd.Flags().BoolVar(
&legacyShow,
"show", false,
"Output scmpuff initialization scripts",
)
InitCmd.Flags().MarkHidden("show")

// --wrap
InitCmd.Flags().BoolVarP(
Expand All @@ -58,9 +65,10 @@ This should probably be evaluated in your shell startup.
// --shell
InitCmd.Flags().StringVarP(
&shellType,
"shell", "", "sh",
"shell", "s", "",
"Set shell type - 'sh' (for bash/zsh), or 'fish'",
)
InitCmd.Flag("shell").NoOptDefVal = "sh"

return InitCmd
}
Expand All @@ -69,9 +77,9 @@ This should probably be evaluated in your shell startup.
func helpString() string {
return `# Initialize scmpuff by adding the following to ~/.bash_profile or ~/.zshrc:
eval "$(scmpuff init -s --shell=sh)"
eval "$(scmpuff init --shell=sh)"
# or the following to ~/.config/fish/config.fish:
scmpuff init -s --shell=fish | source`
scmpuff init --shell=fish | source`
}
10 changes: 4 additions & 6 deletions commands/inits/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ var scriptGitWrapper string
var scriptGitWrapperFish string

func printScript() {
if outputScript {
if shellType == "fish" {
fmt.Println(scriptStatusShortcutsFish)
} else {
fmt.Println(scriptStatusShortcuts)
}
if shellType == "fish" {
fmt.Println(scriptStatusShortcutsFish)
} else {
fmt.Println(scriptStatusShortcuts)
}

if includeAliases {
Expand Down
2 changes: 1 addition & 1 deletion features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

When(/I initialize scmpuff in `(.*)`/) do |shell|
if shell == "fish"
type %{scmpuff init -s --shell=fish | source}
type %{scmpuff init -w --shell=fish | source}
else
type %{eval "$(scmpuff init -ws)"}
end
Expand Down

0 comments on commit d7f2514

Please sign in to comment.