Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli-build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
run: make build-cli

- name: Test
run: go test -v ./cmd/cli
run: make test-cli
2 changes: 1 addition & 1 deletion .github/workflows/service-build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
run: make build-service

- name: Test
run: go test -v ./cmd/service
run: make test-service
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ go.work.sum

# bin file
bin/
oms-cli
oms-service
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
all: build-cli build-service

build-cli:
go build -v -o ./bin/oms-cli ./cmd/cli
cd cli && go build -v && mv cli ../oms-cli

build-service:
go build -v -o ./bin/oms-svc ./cmd/service
cd service && go build -v && mv service ../oms-service

test: test-cli test-service

test-cli:
# -count=1 to disable caching test results
go test -count=1 -v ./cli/...

test-service:
go test -count=1 -v ./service/...
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replaces the formerly used private cloud installer.
### How to Build?

```shell
make build cli
make build-cli
```

### How to Test?
Expand All @@ -24,7 +24,7 @@ make build cli
### How to Build?

```shell
make build service
make build-service
```

### How to Test?
Expand All @@ -33,3 +33,16 @@ make build service
### How to Use?


## How to add a command to one of the binaries?

This project currently uses a fork of cobra-cli with locally-scoped variables: https://github.com/NautiluX/cobra-cli-local

```shell
cobra-cli add -L -d cli -p install postgres
```

This command will add the following command to the CLI:

```shell
oms-cli install postgres
```
54 changes: 54 additions & 0 deletions cli/cmd/install-ceph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// InstallCephCmd represents the ceph command
type InstallCephCmd struct {
cmd *cobra.Command
}

func (c *InstallCephCmd) RunE(_ *cobra.Command, args []string) error {
//Command execution goes here

fmt.Printf("running %s", c.cmd.Use)

return nil
}

func AddInstallCephCmd(install *cobra.Command) {
ceph := InstallCephCmd{
cmd: &cobra.Command{
Use: "ceph",
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.`,
},
}
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// ceph.cmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// ceph.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
install.AddCommand(ceph.cmd)
ceph.cmd.RunE = ceph.RunE

// Add child commands here
// AddCephChildCmd(ceph.cmd)
}

54 changes: 54 additions & 0 deletions cli/cmd/install-codesphere.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// InstallCodesphereCmd represents the codesphere command
type InstallCodesphereCmd struct {
cmd *cobra.Command
}

func (c *InstallCodesphereCmd) RunE(_ *cobra.Command, args []string) error {
//Command execution goes here

fmt.Printf("running %s", c.cmd.Use)

return nil
}

func AddInstallCodesphereCmd(install *cobra.Command) {
codesphere := InstallCodesphereCmd{
cmd: &cobra.Command{
Use: "codesphere",
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.`,
},
}
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// codesphere.cmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// codesphere.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
install.AddCommand(codesphere.cmd)
codesphere.cmd.RunE = codesphere.RunE

// Add child commands here
// AddCodesphereChildCmd(codesphere.cmd)
}

53 changes: 53 additions & 0 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// InstallCmd represents the install command
type InstallCmd struct {
cmd *cobra.Command
}

func (c *InstallCmd) RunE(_ *cobra.Command, args []string) error {
//Command execution goes here

fmt.Printf("running %s", c.cmd.Use)

return nil
}

func AddInstallCmd(rootCmd *cobra.Command) {
install := InstallCmd{
cmd: &cobra.Command{
Use: "install",
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.`,
},
}
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// install.cmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// install.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.AddCommand(install.cmd)
install.cmd.RunE = install.RunE

// Add child commands here
AddInstallCephCmd(install.cmd)
AddInstallCodesphereCmd(install.cmd)
}
46 changes: 46 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)

// 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() {
// rootCmd represents the base command when called without any subcommands
rootCmd := &cobra.Command{
Use: "cli",
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) { },
}
// 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/.cli.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")

// Add child commands here
AddInstallCmd(rootCmd)

err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
54 changes: 54 additions & 0 deletions cli/cmd/upgrade-ceph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// UpgradeCephCmd represents the ceph command
type UpgradeCephCmd struct {
cmd *cobra.Command
}

func (c *UpgradeCephCmd) RunE(_ *cobra.Command, args []string) error {
//Command execution goes here

fmt.Printf("running %s", c.cmd.Use)

return nil
}

func AddUpgradeCephCmd(upgrade *cobra.Command) {
ceph := UpgradeCephCmd{
cmd: &cobra.Command{
Use: "ceph",
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.`,
},
}
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// ceph.cmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// ceph.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
upgrade.AddCommand(ceph.cmd)
ceph.cmd.RunE = ceph.RunE

// Add child commands here
// AddCephChildCmd(ceph.cmd)
}

54 changes: 54 additions & 0 deletions cli/cmd/upgrade-codesphere.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright © 2025 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// UpgradeCodesphereCmd represents the codesphere command
type UpgradeCodesphereCmd struct {
cmd *cobra.Command
}

func (c *UpgradeCodesphereCmd) RunE(_ *cobra.Command, args []string) error {
//Command execution goes here

fmt.Printf("running %s", c.cmd.Use)

return nil
}

func AddUpgradeCodesphereCmd(upgrade *cobra.Command) {
codesphere := UpgradeCodesphereCmd{
cmd: &cobra.Command{
Use: "codesphere",
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.`,
},
}
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// codesphere.cmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// codesphere.cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
upgrade.AddCommand(codesphere.cmd)
codesphere.cmd.RunE = codesphere.RunE

// Add child commands here
// AddCodesphereChildCmd(codesphere.cmd)
}

Loading