diff --git a/cmd/delete.go b/cmd/delete.go new file mode 100644 index 0000000..749776d --- /dev/null +++ b/cmd/delete.go @@ -0,0 +1,49 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(deleteCmd) + rootCmd.Flags().StringP("repo", "R", "", "Select another repository for finding actions cache.") + rootCmd.Flags().StringP("branch", "B", "", "Filter by branch") + deleteCmd.SetHelpTemplate(getDeleteHelp()) +} + +var deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Print the version number of Hugo", + Long: `All software has versions. This is Hugo's`, + Run: func(cmd *cobra.Command, args []string) { + repo, _ := cmd.Flags().GetString("repo") + branch, _ := cmd.Flags().GetString("branch") + fmt.Println("DELETE") + fmt.Println(repo) + fmt.Println(branch) + }, +} + +func getDeleteHelp() string { + return ` +gh-actions-cache: Works with GitHub Actions Cache. + +USAGE: + gh actions-cache lisy [flags] + +ARGUMENTS: + key cache key which needs to be deleted + +FLAGS: + -R, --repo <[HOST/]owner/repo> Select another repository + -B, --branch Filter by branch + +INHERITED FLAGS + --help Show help for command + +EXAMPLES: + $ gh actions-cache delete Linux-node-f5dbf39c9d11eba80242ac13 +` +} diff --git a/cmd/list.go b/cmd/list.go new file mode 100644 index 0000000..eafcf49 --- /dev/null +++ b/cmd/list.go @@ -0,0 +1,63 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(listCmd) + rootCmd.Flags().StringP("repo", "R", "", "Select another repository for finding actions cache.") + rootCmd.Flags().StringP("branch", "B", "", "Filter by branch") + rootCmd.Flags().StringP("key", "", "", "Filter by key") + rootCmd.Flags().StringP("order", "", "", "Order of caches returned (asc/desc)") + rootCmd.Flags().StringP("sort", "", "", "Sort fetched caches (used/size/created)") + listCmd.SetHelpTemplate(getListHelp()) +} + +var listCmd = &cobra.Command{ + Use: "list", + Short: "Print the version number of Hugo", + Long: `All software has versions. This is Hugo's`, + Run: func(cmd *cobra.Command, args []string) { + repo, _ := cmd.Flags().GetString("repo") + branch, _ := cmd.Flags().GetString("branch") + key, _ := cmd.Flags().GetString("key") + order, _ := cmd.Flags().GetString("order") + sort, _ := cmd.Flags().GetString("sort") + fmt.Println("LIST") + fmt.Println(repo) + fmt.Println(branch) + fmt.Println(key) + fmt.Println(order) + fmt.Println(sort) + }, +} + +func getListHelp() string { + return ` +gh-actions-cache: Works with GitHub Actions Cache. + +USAGE: + gh actions-cache lisy [flags] + +ARGUMENTS: + No Arguments + +FLAGS: + -R, --repo <[HOST/]owner/repo> Select another repository + -B, --branch Filter by branch + --key Filter by key + --order Order of caches returned (asc/desc) + --sort Sort fetched caches (used/size/created) + +INHERITED FLAGS + --help Show help for command + +EXAMPLES: + $ gh actions-cache list + $ gh actions-cache list --limit 100 + $ gh actions-cache list --order desc +` +} diff --git a/cmd/root.go b/cmd/root.go index de60543..c5ceb21 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,7 +1,3 @@ -/* -Copyright © 2022 NAME HERE - -*/ package cmd import ( @@ -10,25 +6,13 @@ import ( "github.com/spf13/cobra" ) - - -// rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "gh-actions-cache", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, - // Uncomment the following line if your bare application - // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + Short: "Works with GitHub Actions Cache. ", + Long: `Works with GitHub Actions Cache.`, + // Run: func(cmd *cobra.Command, args []string) {}, } -// Execute adds all child commands to the root command and sets flags appropriately. -// This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { err := rootCmd.Execute() if err != nil { @@ -37,15 +21,28 @@ func Execute() { } func init() { - // Here you will define your flags and configuration settings. - // Cobra supports persistent flags, which, if defined here, - // will be global for your application. - - // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gh-actions-cache.yaml)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.SetHelpTemplate(getRootHelp()) } +func getRootHelp() string { + return ` +gh-actions-cache: Works with GitHub Actions Cache. +USAGE: + gh actions-cache [flags] + +CORE COMMANDS: + list: list caches with result length cap of 100 + delete: delete caches with a key + +INHERITED FLAGS + --help Show help for command + +EXAMPLES: + $ gh actions-cache list + $ gh actions-cache list --limit 100 + $ gh actions-cache list --order desc + $ gh actions-cache delete Linux-node-f5dbf39c9d11eba80242ac13 +` +}