generated from alecodes/base-template
feat: add basic command structure
This commit is contained in:
parent
c8a37ed85c
commit
1459abdd84
8 changed files with 78 additions and 3 deletions
18
cmd/root.go
18
cmd/root.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -37,6 +38,8 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
godotenv.Load()
|
||||
|
||||
cobra.OnInitialize(initConfig)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
|
@ -75,4 +78,19 @@ func initConfig() {
|
|||
if err := viper.ReadInConfig(); err == nil {
|
||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
||||
}
|
||||
|
||||
requiredParams := [...]string{
|
||||
"miniflux_host",
|
||||
"miniflux_token",
|
||||
}
|
||||
|
||||
for _, param := range requiredParams {
|
||||
if !viper.IsSet(param) {
|
||||
fmt.Printf(
|
||||
"Error: The value \"%v\" must be set. For more information use the --help command\n",
|
||||
param,
|
||||
)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue