Skip to content

Commit

Permalink
Cmd (#3)
Browse files Browse the repository at this point in the history
* cmd
* add Makfile
  • Loading branch information
baabeetaa authored Mar 28, 2023
1 parent 7932b31 commit 27f09fd
Show file tree
Hide file tree
Showing 7 changed files with 616 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
build
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
all: install

LD_FLAGS = -w -s


BUILD_FLAGS := -ldflags '$(LD_FLAGS)'

build:
@echo "Building subnode"
@go build -mod readonly $(BUILD_FLAGS) -o build/subnode main.go

install:
@echo "Installing subnode"
@go install -mod readonly $(BUILD_FLAGS) ./...

clean:
rm -rf build

.PHONY: all lint test race msan tools clean build
56 changes: 56 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
configFile string
)

// NewRootCmd returns the root command
func NewRootCmd() *cobra.Command {
// RootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "subnode",
Short: "subnode is a smart reverse proxy server for cosmos based chains",
}

rootCmd.PersistentPreRunE = func(cmd *cobra.Command, _ []string) error {
// reads `subnode.yaml` into `var config *Config` before each command
// if err := initConfig(rootCmd); err != nil {
// return err
// }

return nil
}

// --app flag
rootCmd.PersistentFlags().StringVar(&configFile, "config-file", "subnode.yaml", "path to the config file")
if err := viper.BindPFlag("config-file", rootCmd.PersistentFlags().Lookup("config-file")); err != nil {
panic(err)
}

rootCmd.AddCommand(
startCmd(),
)

return rootCmd
}

// 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() {
cobra.EnableCommandSorting = false

rootCmd := NewRootCmd()
rootCmd.SilenceUsage = true
rootCmd.CompletionOptions.DisableDefaultCmd = true

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
21 changes: 21 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

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

func startCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "start subnode server",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {

fmt.Println("startCmd")

return nil
},
}
return cmd
}
26 changes: 26 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module github.com/notional-labs/subnode

go 1.20

require (
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
)

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
483 changes: 483 additions & 0 deletions go.sum

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/notional-labs/subnode/cmd"
)

func main() {
cmd.Execute()
}

0 comments on commit 27f09fd

Please sign in to comment.