Chris Lu
4 years ago
18 changed files with 152 additions and 23 deletions
-
1go.mod
-
4go.sum
-
4k8s/seaweedfs/Chart.yaml
-
1k8s/seaweedfs/values.yaml
-
109weed/command/autocomplete.go
-
2weed/command/command.go
-
4weed/command/filer_backup.go
-
1weed/command/filer_meta_backup.go
-
1weed/command/filer_meta_tail.go
-
1weed/command/filer_sync.go
-
1weed/command/iam.go
-
2weed/command/scaffold/master.toml
-
4weed/command/upload.go
-
12weed/shell/command_volume_balance.go
-
19weed/shell/command_volume_delete_empty.go
-
2weed/shell/command_volume_fix_replication.go
-
2weed/util/constants.go
-
5weed/weed.go
@ -1,5 +1,5 @@ |
|||||
apiVersion: v1 |
apiVersion: v1 |
||||
description: SeaweedFS |
description: SeaweedFS |
||||
name: seaweedfs |
name: seaweedfs |
||||
appVersion: "2.60" |
|
||||
version: "2.60" |
|
||||
|
appVersion: "2.61" |
||||
|
version: "2.61" |
@ -0,0 +1,109 @@ |
|||||
|
package command |
||||
|
|
||||
|
import ( |
||||
|
"fmt" |
||||
|
flag "github.com/chrislusf/seaweedfs/weed/util/fla9" |
||||
|
"github.com/posener/complete" |
||||
|
completeinstall "github.com/posener/complete/cmd/install" |
||||
|
"runtime" |
||||
|
) |
||||
|
|
||||
|
func AutocompleteMain(commands []*Command) bool { |
||||
|
subCommands := make(map[string]complete.Command) |
||||
|
helpSubCommands := make(map[string]complete.Command) |
||||
|
for _, cmd := range commands { |
||||
|
flags := make(map[string]complete.Predictor) |
||||
|
cmd.Flag.VisitAll(func(flag *flag.Flag) { |
||||
|
flags["-"+flag.Name] = complete.PredictAnything |
||||
|
}) |
||||
|
|
||||
|
subCommands[cmd.Name()] = complete.Command{ |
||||
|
Flags: flags, |
||||
|
} |
||||
|
helpSubCommands[cmd.Name()] = complete.Command{} |
||||
|
} |
||||
|
subCommands["help"] = complete.Command{Sub: helpSubCommands} |
||||
|
|
||||
|
globalFlags := make(map[string]complete.Predictor) |
||||
|
flag.VisitAll(func(flag *flag.Flag) { |
||||
|
globalFlags["-"+flag.Name] = complete.PredictAnything |
||||
|
}) |
||||
|
|
||||
|
weedCmd := complete.Command{ |
||||
|
Sub: subCommands, |
||||
|
Flags: globalFlags, |
||||
|
GlobalFlags: complete.Flags{"-h": complete.PredictNothing}, |
||||
|
} |
||||
|
cmp := complete.New("weed", weedCmd) |
||||
|
|
||||
|
return cmp.Complete() |
||||
|
} |
||||
|
|
||||
|
func installAutoCompletion() bool { |
||||
|
if runtime.GOOS == "windows" { |
||||
|
fmt.Println("windows is not supported") |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
err := completeinstall.Install("weed") |
||||
|
if err != nil { |
||||
|
fmt.Printf("install failed! %s\n", err) |
||||
|
return false |
||||
|
} |
||||
|
fmt.Printf("autocompletion is enabled. Please restart your shell.\n") |
||||
|
return true |
||||
|
} |
||||
|
|
||||
|
func uninstallAutoCompletion() bool { |
||||
|
if runtime.GOOS == "windows" { |
||||
|
fmt.Println("windows is not supported") |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
err := completeinstall.Uninstall("weed") |
||||
|
if err != nil { |
||||
|
fmt.Printf("uninstall failed! %s\n", err) |
||||
|
return false |
||||
|
} |
||||
|
fmt.Printf("autocompletion is disable. Please restart your shell.\n") |
||||
|
return true |
||||
|
} |
||||
|
|
||||
|
var cmdAutocomplete = &Command{ |
||||
|
Run: runAutocomplete, |
||||
|
UsageLine: "autocomplete", |
||||
|
Short: "install autocomplete", |
||||
|
Long: `weed autocomplete is installed in the shell. |
||||
|
|
||||
|
Supported shells are bash, zsh, and fish. |
||||
|
Windows is not supported. |
||||
|
|
||||
|
`, |
||||
|
} |
||||
|
|
||||
|
func runAutocomplete(cmd *Command, args []string) bool { |
||||
|
if len(args) != 0 { |
||||
|
cmd.Usage() |
||||
|
} |
||||
|
|
||||
|
return installAutoCompletion() |
||||
|
} |
||||
|
|
||||
|
var cmdUnautocomplete = &Command{ |
||||
|
Run: runUnautocomplete, |
||||
|
UsageLine: "autocomplete.uninstall", |
||||
|
Short: "uninstall autocomplete", |
||||
|
Long: `weed autocomplete is uninstalled in the shell. |
||||
|
|
||||
|
Windows is not supported. |
||||
|
|
||||
|
`, |
||||
|
} |
||||
|
|
||||
|
func runUnautocomplete(cmd *Command, args []string) bool { |
||||
|
if len(args) != 0 { |
||||
|
cmd.Usage() |
||||
|
} |
||||
|
|
||||
|
return uninstallAutoCompletion() |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue