refactor: improve command line flag descriptions and variable names

This commit is contained in:
Prad Nukala 2024-12-10 15:27:36 -05:00
parent 1250468f69
commit 45bc823de0
2 changed files with 21 additions and 21 deletions

View File

@ -19,17 +19,17 @@ import (
// Command line flags // Command line flags
var ( var (
servePort int servePort int // Gateway http entry point (default 3000)
configDir string configDir string // Hway config directory (default hway)
sqliteFile string sqliteFile string // SQLite database file (default hway.db)
chainId string chainID string // Current chain ID (default sonr-testnet-1)
ipfsGatewayUrl string ipfsGatewayURL string // IPFS gateway URL (default localhost:8080)
sonrApiUrl string sonrAPIURL string // Sonr API URL (default localhost:1317)
sonrGrpcUrl string sonrGrpcURL string // Sonr gRPC URL (default localhost:9090)
sonrRpcUrl string sonrRPCURL string // Sonr RPC URL (default localhost:26657)
) )
func NewRootCmd() *cobra.Command { func rootCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "hway", Use: "hway",
Short: "Sonr DID gateway", Short: "Sonr DID gateway",
@ -52,16 +52,16 @@ func NewRootCmd() *cobra.Command {
cmd.Flags().IntVar(&servePort, "serve-port", 3000, "Port to serve the gateway on") cmd.Flags().IntVar(&servePort, "serve-port", 3000, "Port to serve the gateway on")
cmd.Flags().StringVar(&configDir, "config-dir", "hway", "Directory to store config files") cmd.Flags().StringVar(&configDir, "config-dir", "hway", "Directory to store config files")
cmd.Flags().StringVar(&sqliteFile, "sqlite-file", "hway.db", "File to store sqlite database") cmd.Flags().StringVar(&sqliteFile, "sqlite-file", "hway.db", "File to store sqlite database")
cmd.Flags().StringVar(&chainId, "chain-id", "sonr-testnet-1", "Chain ID") cmd.Flags().StringVar(&chainID, "chain-id", "sonr-testnet-1", "Chain ID")
cmd.Flags().StringVar(&ipfsGatewayUrl, "ipfs-gateway-url", "localhost:8080", "IPFS gateway URL") cmd.Flags().StringVar(&ipfsGatewayURL, "ipfs-gateway-url", "localhost:8080", "IPFS gateway URL")
cmd.Flags().StringVar(&sonrApiUrl, "sonr-api-url", "localhost:1317", "Sonr API URL") cmd.Flags().StringVar(&sonrAPIURL, "sonr-api-url", "localhost:1317", "Sonr API URL")
cmd.Flags().StringVar(&sonrGrpcUrl, "sonr-grpc-url", "localhost:9090", "Sonr gRPC URL") cmd.Flags().StringVar(&sonrGrpcURL, "sonr-grpc-url", "localhost:9090", "Sonr gRPC URL")
cmd.Flags().StringVar(&sonrRpcUrl, "sonr-rpc-url", "localhost:26657", "Sonr RPC URL") cmd.Flags().StringVar(&sonrRPCURL, "sonr-rpc-url", "localhost:26657", "Sonr RPC URL")
return cmd return cmd
} }
func loadEnvImplFromArgs(args []string) (config.Env, error) { func loadEnvImplFromArgs(args []string) (config.Env, error) {
cmd := NewRootCmd() cmd := rootCmd()
if err := cmd.ParseFlags(args); err != nil { if err := cmd.ParseFlags(args); err != nil {
return nil, err return nil, err
} }
@ -70,11 +70,11 @@ func loadEnvImplFromArgs(args []string) (config.Env, error) {
ServePort: servePort, ServePort: servePort,
ConfigDir: configDir, ConfigDir: configDir,
SqliteFile: sqliteFile, SqliteFile: sqliteFile,
ChainId: chainId, ChainId: chainID,
IpfsGatewayUrl: ipfsGatewayUrl, IpfsGatewayUrl: ipfsGatewayURL,
SonrApiUrl: sonrApiUrl, SonrApiUrl: sonrAPIURL,
SonrGrpcUrl: sonrGrpcUrl, SonrGrpcUrl: sonrGrpcURL,
SonrRpcUrl: sonrRpcUrl, SonrRpcUrl: sonrRPCURL,
} }
return env, nil return env, nil
} }

View File

@ -8,7 +8,7 @@ import (
// main is the entry point for the application // main is the entry point for the application
func main() { func main() {
cmd := NewRootCmd() cmd := rootCmd()
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)