Skip to content

Commit

Permalink
cli: setup CLI with cobra
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanix-Darker committed Apr 23, 2022
1 parent 0008821 commit 7f10ea9
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sami-cli/cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"errors"
"fmt"

"github.com/spf13/cobra"
)

//NewDeployCommand create new cobra command for the init command
func NewDeployCommand() *cobra.Command {
command := &cobra.Command{
Use: "deploy -f <deployment_sami_file>",
Short: "deloy your service by given the deployment sami file",
Long: `deloy your service by given the deployment sami file
example: sami deploy -f <deploy-path>/<sami.yaml>
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
deployFolder := args[0]

if err := deployCommand(deployFolder); err != nil {
fmt.Printf("Error: %s\n", err)
return
}
},
}

return command
}

func deployCommand(deployFolder string) error {
// will add the deployment process here...
return errors.New("")
}
27 changes: 27 additions & 0 deletions sami-cli/cmd/sami.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"github.com/spf13/cobra"
)

//NewCommand returns a new sami cobra command
func NewCommand() *cobra.Command {
var samiCommand = &cobra.Command{
Use: "sami",
Short: "sami helps you deploy your services to any target machine",
Long: `sami helps you deploy your services to any target machine`,
}

// deploy
// samiCommand.AddCommand(NewDeployCommand())

// logs
// samiCommand.AddCommand(NewLogsCommand())

// oob
// samiCommand.AddCommand(NewOobCommand())

// status
// samiCommand.AddCommand(NewStatusCommand())
return samiCommand
}
12 changes: 12 additions & 0 deletions sami-cli/fixtures/bad-sami.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


service_name: "camerdevs"
type: "swarm"

files:
- ./stack.yaml

oob:
- update-image:
file: "./stack.yaml"
zigzag: 1
12 changes: 12 additions & 0 deletions sami-cli/fixtures/good-sami.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: v1beta


service_name: "camerdevs"
type: "swarm"
files:
- ./stack.yaml

oob:
- update-image:
file: "./stack.yaml"
path: ".services.frontend.image"
10 changes: 10 additions & 0 deletions sami-cli/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/osscameroon/sami

go 1.17

require github.com/spf13/cobra v1.4.0

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
10 changes: 10 additions & 0 deletions sami-cli/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
20 changes: 20 additions & 0 deletions sami-cli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"os"

"github.com/osscameroon/sami/sami-cli/cmd"
)

var version = "0.0.0+dev"

func main() {
command := cmd.NewCommand()

err := command.Execute()
if err != nil {
os.Exit(1)
}

os.Exit(0)
}

0 comments on commit 7f10ea9

Please sign in to comment.