added list and delete commands

This commit is contained in:
t-dedah
2022-06-11 02:20:36 +05:30
parent 45f4742cec
commit 58d1be62e6
3 changed files with 136 additions and 27 deletions

49
cmd/delete.go Normal file
View File

@@ -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 <string> Filter by branch
INHERITED FLAGS
--help Show help for command
EXAMPLES:
$ gh actions-cache delete Linux-node-f5dbf39c9d11eba80242ac13
`
}

63
cmd/list.go Normal file
View File

@@ -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 <string> Filter by branch
--key <string> Filter by key
--order <string> Order of caches returned (asc/desc)
--sort <string> 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
`
}

View File

@@ -1,7 +1,3 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
*/
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 <command> [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
`
}