Redmage/cli/cli.go

37 lines
696 B
Go
Raw Permalink Normal View History

2024-04-06 01:22:00 +07:00
package cli
2024-04-07 12:11:25 +07:00
import (
"fmt"
"github.com/spf13/cobra"
"github.com/tigorlazuardi/redmage/config"
)
2024-04-06 01:22:00 +07:00
var RootCmd = &cobra.Command{
Use: "redmage",
Short: "Redmage is an HTTP server to download images from Reddit.",
}
2024-04-07 12:11:25 +07:00
func init() {
flags := RootCmd.PersistentFlags()
for key, value := range config.DefaultConfig {
const usage = ""
switch v := value.(type) {
case bool:
flags.Bool(key, v, usage)
case string:
flags.String(key, v, usage)
case int:
flags.Int(key, v, usage)
case float32:
flags.Float32(key, v, usage)
case float64:
flags.Float64(key, v, usage)
default:
flags.String(key, fmt.Sprintf("%v", v), usage)
}
}
cobra.OnInitialize(initConfig)
}