From 2e6b4b208e99e59c43d50200caa05cc7cd5c3678 Mon Sep 17 00:00:00 2001 From: xtaci Date: Fri, 9 Aug 2024 12:00:35 +0800 Subject: [PATCH] init command line tools --- cmd/hppktool/LICENSE | 0 cmd/hppktool/cmd/encrypt.go | 40 ++++++++++++++++++++++++++++++++++++ cmd/hppktool/cmd/keygen.go | 40 ++++++++++++++++++++++++++++++++++++ cmd/hppktool/cmd/root.go | 41 +++++++++++++++++++++++++++++++++++++ cmd/hppktool/cmd/sign.go | 40 ++++++++++++++++++++++++++++++++++++ cmd/hppktool/cmd/verify.go | 40 ++++++++++++++++++++++++++++++++++++ cmd/hppktool/main.go | 10 +++++++++ go.mod | 3 +++ go.sum | 8 ++++++++ 9 files changed, 222 insertions(+) create mode 100644 cmd/hppktool/LICENSE create mode 100644 cmd/hppktool/cmd/encrypt.go create mode 100644 cmd/hppktool/cmd/keygen.go create mode 100644 cmd/hppktool/cmd/root.go create mode 100644 cmd/hppktool/cmd/sign.go create mode 100644 cmd/hppktool/cmd/verify.go create mode 100644 cmd/hppktool/main.go diff --git a/cmd/hppktool/LICENSE b/cmd/hppktool/LICENSE new file mode 100644 index 0000000..e69de29 diff --git a/cmd/hppktool/cmd/encrypt.go b/cmd/hppktool/cmd/encrypt.go new file mode 100644 index 0000000..3ce8423 --- /dev/null +++ b/cmd/hppktool/cmd/encrypt.go @@ -0,0 +1,40 @@ +/* +Copyright © 2024 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// encryptCmd represents the encrypt command +var encryptCmd = &cobra.Command{ + Use: "encrypt", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. 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.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("encrypt called") + }, +} + +func init() { + rootCmd.AddCommand(encryptCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // encryptCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // encryptCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/hppktool/cmd/keygen.go b/cmd/hppktool/cmd/keygen.go new file mode 100644 index 0000000..467db50 --- /dev/null +++ b/cmd/hppktool/cmd/keygen.go @@ -0,0 +1,40 @@ +/* +Copyright © 2024 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// keygenCmd represents the keygen command +var keygenCmd = &cobra.Command{ + Use: "keygen", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. 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.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("keygen called") + }, +} + +func init() { + rootCmd.AddCommand(keygenCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // keygenCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // keygenCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/hppktool/cmd/root.go b/cmd/hppktool/cmd/root.go new file mode 100644 index 0000000..a8bae54 --- /dev/null +++ b/cmd/hppktool/cmd/root.go @@ -0,0 +1,41 @@ +/* +Copyright © 2024 NAME HERE +*/ +package cmd + +import ( + "os" + + "github.com/spf13/cobra" +) + +// rootCmd represents the base command when called without any subcommands +var rootCmd = &cobra.Command{ + Use: "hppktool", + Short: "HPPK key management tool", + Long: `Key generation, signing, verification, and secret encryption tool for HPPK.`, + // Uncomment the following line if your bare application + // has an action associated with it: + // 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 { + os.Exit(1) + } +} + +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/.hppktool.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") +} diff --git a/cmd/hppktool/cmd/sign.go b/cmd/hppktool/cmd/sign.go new file mode 100644 index 0000000..45b1336 --- /dev/null +++ b/cmd/hppktool/cmd/sign.go @@ -0,0 +1,40 @@ +/* +Copyright © 2024 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// signCmd represents the sign command +var signCmd = &cobra.Command{ + Use: "sign", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. 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.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("sign called") + }, +} + +func init() { + rootCmd.AddCommand(signCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // signCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // signCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/hppktool/cmd/verify.go b/cmd/hppktool/cmd/verify.go new file mode 100644 index 0000000..51a9140 --- /dev/null +++ b/cmd/hppktool/cmd/verify.go @@ -0,0 +1,40 @@ +/* +Copyright © 2024 NAME HERE + +*/ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// verifyCmd represents the verify command +var verifyCmd = &cobra.Command{ + Use: "verify", + Short: "A brief description of your command", + Long: `A longer description that spans multiple lines and likely contains examples +and usage of using your command. 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.`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("verify called") + }, +} + +func init() { + rootCmd.AddCommand(verifyCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // verifyCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // verifyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") +} diff --git a/cmd/hppktool/main.go b/cmd/hppktool/main.go new file mode 100644 index 0000000..16a2927 --- /dev/null +++ b/cmd/hppktool/main.go @@ -0,0 +1,10 @@ +/* +Copyright © 2024 xtaci +*/ +package main + +import "github.com/xtaci/hppk/cmd/hppktool/cmd" + +func main() { + cmd.Execute() +} diff --git a/go.mod b/go.mod index 23b824d..0e7cde0 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,10 @@ go 1.22.5 require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/cobra v1.8.1 // indirect + github.com/spf13/pflag v1.0.5 // indirect github.com/stretchr/testify v1.9.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e20fa14..c7da2f0 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,15 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=