Skip to content

Commit f4725d8

Browse files
committed
chore(org): Update project setup
* separation of cli and service * generate commands with CLI that supports local scope
1 parent f41a9e6 commit f4725d8

23 files changed

+469
-280
lines changed

.github/workflows/cli-build_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
run: make build-cli
2626

2727
- name: Test
28-
run: go test -v ./cmd/cli
28+
run: make test-cli

.github/workflows/service-build_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
run: make build-service
2626

2727
- name: Test
28-
run: go test -v ./cmd/service
28+
run: make test-service

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ go.work.sum
2626

2727
# bin file
2828
bin/
29+
oms-cli
30+
oms-service

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
all: build-cli build-service
2+
13
build-cli:
2-
go build -v -o ./bin/oms-cli ./cmd/cli
4+
cd cli && go build -v && mv cli ../oms-cli
35

46
build-service:
5-
go build -v -o ./bin/oms-svc ./cmd/service
7+
cd service && go build -v && mv service ../oms-service
8+
9+
test: test-cli test-service
10+
11+
test-cli:
12+
# -count=1 to disable caching test results
13+
go test -count=1 -v ./cli/...
614

15+
test-service:
16+
go test -count=1 -v ./service/...

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ replaces the formerly used private cloud installer.
1010
### How to Build?
1111

1212
```shell
13-
make build cli
13+
make build-cli
1414
```
1515

1616
### How to Test?
@@ -24,7 +24,7 @@ make build cli
2424
### How to Build?
2525

2626
```shell
27-
make build service
27+
make build-service
2828
```
2929

3030
### How to Test?
@@ -33,3 +33,16 @@ make build service
3333
### How to Use?
3434

3535

36+
## How to add a command to one of the binaries?
37+
38+
This project currently uses a fork of cobra-cli with locally-scoped variables: https://github.com/NautiluX/cobra-cli-local
39+
40+
```shell
41+
cobra-cli add -d cli -p install postgres
42+
```
43+
44+
This command will add the following command to the CLI:
45+
46+
```shell
47+
oms-cli install postgres
48+
```

cli/cmd/install-ceph.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// InstallCephCmd represents the ceph command
14+
type InstallCephCmd struct {
15+
cmd *cobra.Command
16+
}
17+
18+
func (c *InstallCephCmd) RunE(_ *cobra.Command, args []string) error {
19+
//Command execution goes here
20+
21+
fmt.Printf("running %s", c.cmd.Use)
22+
23+
return nil
24+
}
25+
26+
func AddInstallCephCmd(install *cobra.Command) {
27+
ceph := InstallCephCmd{
28+
cmd: &cobra.Command{
29+
Use: "ceph",
30+
Short: "A brief description of your command",
31+
Long: `A longer description that spans multiple lines and likely contains examples
32+
and usage of using your command. For example:
33+
34+
Cobra is a CLI library for Go that empowers applications.
35+
This application is a tool to generate the needed files
36+
to quickly create a Cobra application.`,
37+
},
38+
}
39+
// Here you will define your flags and configuration settings.
40+
41+
// Cobra supports Persistent Flags which will work for this command
42+
// and all subcommands, e.g.:
43+
// ceph.cmd.PersistentFlags().String("foo", "", "A help for foo")
44+
45+
// Cobra supports local flags which will only run when this command
46+
// is called directly, e.g.:
47+
// ceph.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
48+
install.AddCommand(ceph.cmd)
49+
ceph.cmd.RunE = ceph.RunE
50+
51+
// Add child commands here
52+
// AddCephChildCmd(ceph.cmd)
53+
}
54+

cli/cmd/install-codesphere.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// InstallCodesphereCmd represents the codesphere command
14+
type InstallCodesphereCmd struct {
15+
cmd *cobra.Command
16+
}
17+
18+
func (c *InstallCodesphereCmd) RunE(_ *cobra.Command, args []string) error {
19+
//Command execution goes here
20+
21+
fmt.Printf("running %s", c.cmd.Use)
22+
23+
return nil
24+
}
25+
26+
func AddInstallCodesphereCmd(install *cobra.Command) {
27+
codesphere := InstallCodesphereCmd{
28+
cmd: &cobra.Command{
29+
Use: "codesphere",
30+
Short: "A brief description of your command",
31+
Long: `A longer description that spans multiple lines and likely contains examples
32+
and usage of using your command. For example:
33+
34+
Cobra is a CLI library for Go that empowers applications.
35+
This application is a tool to generate the needed files
36+
to quickly create a Cobra application.`,
37+
},
38+
}
39+
// Here you will define your flags and configuration settings.
40+
41+
// Cobra supports Persistent Flags which will work for this command
42+
// and all subcommands, e.g.:
43+
// codesphere.cmd.PersistentFlags().String("foo", "", "A help for foo")
44+
45+
// Cobra supports local flags which will only run when this command
46+
// is called directly, e.g.:
47+
// codesphere.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
48+
install.AddCommand(codesphere.cmd)
49+
codesphere.cmd.RunE = codesphere.RunE
50+
51+
// Add child commands here
52+
// AddCodesphereChildCmd(codesphere.cmd)
53+
}
54+

cli/cmd/install.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// InstallCmd represents the install command
13+
type InstallCmd struct {
14+
cmd *cobra.Command
15+
}
16+
17+
func (c *InstallCmd) RunE(_ *cobra.Command, args []string) error {
18+
//Command execution goes here
19+
20+
fmt.Printf("running %s", c.cmd.Use)
21+
22+
return nil
23+
}
24+
25+
func AddInstallCmd(rootCmd *cobra.Command) {
26+
install := InstallCmd{
27+
cmd: &cobra.Command{
28+
Use: "install",
29+
Short: "A brief description of your command",
30+
Long: `A longer description that spans multiple lines and likely contains examples
31+
and usage of using your command. For example:
32+
33+
Cobra is a CLI library for Go that empowers applications.
34+
This application is a tool to generate the needed files
35+
to quickly create a Cobra application.`,
36+
},
37+
}
38+
// Here you will define your flags and configuration settings.
39+
40+
// Cobra supports Persistent Flags which will work for this command
41+
// and all subcommands, e.g.:
42+
// install.cmd.PersistentFlags().String("foo", "", "A help for foo")
43+
44+
// Cobra supports local flags which will only run when this command
45+
// is called directly, e.g.:
46+
// install.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
47+
rootCmd.AddCommand(install.cmd)
48+
install.cmd.RunE = install.RunE
49+
50+
// Add child commands here
51+
AddInstallCephCmd(install.cmd)
52+
AddInstallCodesphereCmd(install.cmd)
53+
}

cli/cmd/root.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"os"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// Execute adds all child commands to the root command and sets flags appropriately.
13+
// This is called by main.main(). It only needs to happen once to the rootCmd.
14+
func Execute() {
15+
// rootCmd represents the base command when called without any subcommands
16+
rootCmd := &cobra.Command{
17+
Use: "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+
// Here you will define your flags and configuration settings.
30+
// Cobra supports persistent flags, which, if defined here,
31+
// will be global for your application.
32+
33+
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cli.yaml)")
34+
35+
// Cobra also supports local flags, which will only run
36+
// when this action is called directly.
37+
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
38+
39+
// Add child commands here
40+
AddInstallCmd(rootCmd)
41+
42+
err := rootCmd.Execute()
43+
if err != nil {
44+
os.Exit(1)
45+
}
46+
}

cli/cmd/upgrade-ceph.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
3+
4+
*/
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// UpgradeCephCmd represents the ceph command
14+
type UpgradeCephCmd struct {
15+
cmd *cobra.Command
16+
}
17+
18+
func (c *UpgradeCephCmd) RunE(_ *cobra.Command, args []string) error {
19+
//Command execution goes here
20+
21+
fmt.Printf("running %s", c.cmd.Use)
22+
23+
return nil
24+
}
25+
26+
func AddUpgradeCephCmd(upgrade *cobra.Command) {
27+
ceph := UpgradeCephCmd{
28+
cmd: &cobra.Command{
29+
Use: "ceph",
30+
Short: "A brief description of your command",
31+
Long: `A longer description that spans multiple lines and likely contains examples
32+
and usage of using your command. For example:
33+
34+
Cobra is a CLI library for Go that empowers applications.
35+
This application is a tool to generate the needed files
36+
to quickly create a Cobra application.`,
37+
},
38+
}
39+
// Here you will define your flags and configuration settings.
40+
41+
// Cobra supports Persistent Flags which will work for this command
42+
// and all subcommands, e.g.:
43+
// ceph.cmd.PersistentFlags().String("foo", "", "A help for foo")
44+
45+
// Cobra supports local flags which will only run when this command
46+
// is called directly, e.g.:
47+
// ceph.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
48+
upgrade.AddCommand(ceph.cmd)
49+
ceph.cmd.RunE = ceph.RunE
50+
51+
// Add child commands here
52+
// AddCephChildCmd(ceph.cmd)
53+
}
54+

0 commit comments

Comments
 (0)