diff --git a/completers/pacman-mirrors_completer/cmd/root.go b/completers/pacman-mirrors_completer/cmd/root.go new file mode 100644 index 0000000000..fe150b52a0 --- /dev/null +++ b/completers/pacman-mirrors_completer/cmd/root.go @@ -0,0 +1,61 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/tools/pacman" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "pacman-mirrors", + Short: "generate pacman mirrorlist", + Long: "https://wiki.manjaro.org/index.php?title=Pacman-mirrors", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} +func init() { + carapace.Gen(rootCmd).Standalone() + + rootCmd.Flags().StringS("S", "S", "", "API: Replace branch in configuration") + rootCmd.Flags().BoolP("api", "a", false, "TODO") + rootCmd.Flags().Bool("continent", false, "Use continent from geolocation") + rootCmd.Flags().StringP("country", "c", "", "Comma separated list of countries, from which mirrors will be used") + rootCmd.Flags().BoolP("country-config", "lc", false, "lists configured mirror countries") + rootCmd.Flags().Bool("country-list", false, "List all available countries") + rootCmd.Flags().BoolP("default", "d", false, "INTERACTIVE: Load default mirror file") + rootCmd.Flags().StringP("fasttrack", "f", "", "Generate mirrorlist with a number of up-to-date mirrors") + rootCmd.Flags().BoolS("fc", "fc", false, "TODO") + rootCmd.Flags().BoolS("g", "g", false, "Create mirror list from active pool.") + rootCmd.Flags().Bool("geoip", false, "Get current country using geolocation") + rootCmd.Flags().BoolP("get-branch", "G", false, "Return branch from configuration") + rootCmd.Flags().BoolP("help", "h", false, "") + rootCmd.Flags().BoolP("interactive", "i", false, "Generate custom mirrorlist") + rootCmd.Flags().String("interval", "", "Max. number of hours since last sync") + rootCmd.Flags().BoolP("list", "l", false, "List all available countries") + rootCmd.Flags().StringP("method", "m", "", "Generation method") + rootCmd.Flags().Bool("no-color", false, "Disable color") + rootCmd.Flags().BoolP("no-mirrorlist", "n", false, "Use to skip generation of mirrorlist") + rootCmd.Flags().BoolP("no-status", "s", false, "Ignore mirror branch status") + rootCmd.Flags().StringP("prefix", "p", "", "API: Set prefix to : $mnt | /mnt/install") + rootCmd.Flags().StringP("proto", "P", "", "API: Replace protocols in configuration") + rootCmd.Flags().String("protocols", "", "API: Replace protocols in configuration") + rootCmd.Flags().BoolP("quiet", "q", false, "Quiet mode - less verbose output") + rootCmd.Flags().BoolP("re-branch", "R", false, "API: Replace branch in mirrorlist") + rootCmd.Flags().StringP("set-branch", "B", "", "API: Replace branch in configuration") + rootCmd.Flags().Bool("status", false, "Status for the current mirror list.") + rootCmd.Flags().StringP("timeout", "t", "", "Maximum waiting time for server response") + rootCmd.Flags().StringP("url", "U", "", "API: Replace mirror url in mirrorlist") + rootCmd.Flags().BoolP("version", "v", false, "Print the pacman-mirrors version") + + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ + "S": carapace.ActionValues("stable", "testing", "unstable"), + "country": pacman.ActionCountries().UniqueList(","), + "method": carapace.ActionValues("rank", "random"), + "proto": carapace.ActionValues("all", "http", "https", "ftp", "ftps").UniqueList(","), + "protocols": carapace.ActionValues("all", "http", "https", "ftp", "ftps").UniqueList(","), + "set-branch": carapace.ActionValues("stable", "testing", "unstable"), + }) +} diff --git a/completers/pacman-mirrors_completer/main.go b/completers/pacman-mirrors_completer/main.go new file mode 100644 index 0000000000..44750351d4 --- /dev/null +++ b/completers/pacman-mirrors_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/rsteube/carapace-bin/completers/pacman-mirrors_completer/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/actions/tools/pacman/country.go b/pkg/actions/tools/pacman/country.go new file mode 100644 index 0000000000..207f4d2e86 --- /dev/null +++ b/pkg/actions/tools/pacman/country.go @@ -0,0 +1,18 @@ +package pacman + +import ( + "strings" + + "github.com/rsteube/carapace" +) + +// ActionCountries completes mirror countries +// +// Armenia +// Australia +func ActionCountries() carapace.Action { + return carapace.ActionExecCommand("pacman-mirrors", "--country-list")(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + return carapace.ActionValues(lines[:len(lines)-1]...) + }) +}