2022-07-17 18:16:00 +00:00
|
|
|
// Copyright (C) 2019-2022 Nicola Murino
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2020-07-08 21:21:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var genCompletionCmd = &cobra.Command{
|
|
|
|
Use: "completion [bash|zsh|fish|powershell]",
|
2021-10-03 06:14:57 +00:00
|
|
|
Short: "Generate the autocompletion script for the specified shell",
|
|
|
|
Long: `Generate the autocompletion script for sftpgo for the specified shell.
|
|
|
|
|
|
|
|
See each sub-command's help for details on how to use the generated script.
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
|
|
|
|
var genCompletionBashCmd = &cobra.Command{
|
|
|
|
Use: "bash",
|
|
|
|
Short: "Generate the autocompletion script for bash",
|
|
|
|
Long: `Generate the autocompletion script for the bash shell.
|
|
|
|
|
|
|
|
This script depends on the 'bash-completion' package.
|
|
|
|
If it is not installed already, you can install it via your OS's package
|
|
|
|
manager.
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions in your current shell session:
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2020-07-11 11:03:15 +00:00
|
|
|
$ source <(sftpgo gen completion bash)
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions for every new session, execute once:
|
2020-10-17 20:14:04 +00:00
|
|
|
|
2020-07-08 21:21:33 +00:00
|
|
|
Linux:
|
2021-10-03 06:14:57 +00:00
|
|
|
$ sudo sftpgo gen completion bash > /usr/share/bash-completion/completions/sftpgo
|
2020-10-17 20:14:04 +00:00
|
|
|
|
2020-07-08 21:21:33 +00:00
|
|
|
MacOS:
|
2021-10-03 06:14:57 +00:00
|
|
|
$ sudo sftpgo gen completion bash > /usr/local/etc/bash_completion.d/sftpgo
|
2020-10-17 20:14:04 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
You will need to start a new shell for this setup to take effect.
|
|
|
|
`,
|
|
|
|
DisableFlagsInUseLine: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return cmd.Root().GenBashCompletionV2(os.Stdout, true)
|
|
|
|
},
|
|
|
|
}
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
var genCompletionZshCmd = &cobra.Command{
|
|
|
|
Use: "zsh",
|
|
|
|
Short: "Generate the autocompletion script for zsh",
|
|
|
|
Long: `Generate the autocompletion script for the zsh shell.
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2020-10-17 20:14:04 +00:00
|
|
|
If shell completion is not already enabled in your environment you will need
|
|
|
|
to enable it. You can execute the following once:
|
|
|
|
|
|
|
|
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions for every new session, execute once:
|
|
|
|
|
|
|
|
Linux:
|
|
|
|
$ sftpgo gen completion zsh > > "${fpath[1]}/_sftpgo"
|
|
|
|
|
|
|
|
macOS:
|
|
|
|
$ sudo sftpgo gen completion zsh > /usr/local/share/zsh/site-functions/_sftpgo
|
|
|
|
|
|
|
|
You will need to start a new shell for this setup to take effect.
|
|
|
|
`,
|
|
|
|
DisableFlagsInUseLine: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return cmd.Root().GenZshCompletion(os.Stdout)
|
|
|
|
},
|
|
|
|
}
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
var genCompletionFishCmd = &cobra.Command{
|
|
|
|
Use: "fish",
|
|
|
|
Short: "Generate the autocompletion script for fish",
|
|
|
|
Long: `Generate the autocompletion script for the fish shell.
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions in your current shell session:
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2020-07-11 11:03:15 +00:00
|
|
|
$ sftpgo gen completion fish | source
|
2020-07-08 21:21:33 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions for every new session, execute once:
|
2020-10-17 20:14:04 +00:00
|
|
|
|
2020-07-24 21:39:38 +00:00
|
|
|
$ sftpgo gen completion fish > ~/.config/fish/completions/sftpgo.fish
|
2021-02-13 08:10:35 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
You will need to start a new shell for this setup to take effect.
|
|
|
|
`,
|
|
|
|
DisableFlagsInUseLine: true,
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return cmd.Root().GenFishCompletion(os.Stdout, true)
|
|
|
|
},
|
|
|
|
}
|
2021-02-13 08:10:35 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
var genCompletionPowerShellCmd = &cobra.Command{
|
|
|
|
Use: "powershell",
|
|
|
|
Short: "Generate the autocompletion script for powershell",
|
|
|
|
Long: `Generate the autocompletion script for powershell.
|
2021-02-13 08:10:35 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions in your current shell session:
|
2021-02-13 08:10:35 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
PS C:\> sftpgo gen completion powershell | Out-String | Invoke-Expression
|
2021-02-13 08:10:35 +00:00
|
|
|
|
2021-10-03 06:14:57 +00:00
|
|
|
To load completions for every new session, add the output of the above command
|
|
|
|
to your powershell profile.
|
2020-07-08 21:21:33 +00:00
|
|
|
`,
|
|
|
|
DisableFlagsInUseLine: true,
|
2021-10-03 06:14:57 +00:00
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
|
2020-07-08 21:21:33 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2021-10-03 06:14:57 +00:00
|
|
|
genCompletionCmd.AddCommand(genCompletionBashCmd)
|
|
|
|
genCompletionCmd.AddCommand(genCompletionZshCmd)
|
|
|
|
genCompletionCmd.AddCommand(genCompletionFishCmd)
|
|
|
|
genCompletionCmd.AddCommand(genCompletionPowerShellCmd)
|
|
|
|
|
2020-07-08 21:21:33 +00:00
|
|
|
genCmd.AddCommand(genCompletionCmd)
|
|
|
|
}
|