Skip to content

Commit 10c8d5b

Browse files
author
Gyeongjun Paik
committed
Init: Cobra CLI project
1 parent 2174877 commit 10c8d5b

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

LICENSE

Whitespace-only changes.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### 1. Install
22
1. go mod init hello-cli
33
2. go get -u github.com/spf13/cobra
4+
3. cobra-cli init
45

cmd/root.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"os"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
14+
15+
// rootCmd represents the base command when called without any subcommands
16+
var rootCmd = &cobra.Command{
17+
Use: "hello-cli",
18+
Short: "A brief description of your application",
19+
Long: `A longer description that spans multiple lines and likely contains
20+
examples and usage of using your application. For example:
21+
22+
Cobra is a CLI library for Go that empowers applications.
23+
This application is a tool to generate the needed files
24+
to quickly create a Cobra application.`,
25+
// Uncomment the following line if your bare application
26+
// has an action associated with it:
27+
// Run: func(cmd *cobra.Command, args []string) { },
28+
}
29+
30+
// Execute adds all child commands to the root command and sets flags appropriately.
31+
// This is called by main.main(). It only needs to happen once to the rootCmd.
32+
func Execute() {
33+
err := rootCmd.Execute()
34+
if err != nil {
35+
os.Exit(1)
36+
}
37+
}
38+
39+
func init() {
40+
// Here you will define your flags and configuration settings.
41+
// Cobra supports persistent flags, which, if defined here,
42+
// will be global for your application.
43+
44+
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.hello-cli.yaml)")
45+
46+
// Cobra also supports local flags, which will only run
47+
// when this action is called directly.
48+
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
49+
}
50+
51+

main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package main
6+
7+
import "hello-cli/cmd"
8+
9+
func main() {
10+
cmd.Execute()
11+
}

0 commit comments

Comments
 (0)