aboutsummaryrefslogtreecommitdiff
path: root/cmd/root.go
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-30 15:10:58 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-30 15:10:58 +0530
commitd67758bdbeb162adadb6b19954e8e22cf04ed388 (patch)
tree1438369c1d980ebb041a04264da6d9006473e967 /cmd/root.go
parent37b5c5457d51b50af1dcadaf7c85be7e7349d682 (diff)
reading both flags and config for searching commands
Diffstat (limited to 'cmd/root.go')
-rw-r--r--cmd/root.go41
1 files changed, 29 insertions, 12 deletions
diff --git a/cmd/root.go b/cmd/root.go
index 02d27a1..7b379a3 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -30,14 +30,14 @@ var (
queryOnlyMode, mangaMode bool
entryId int
- // auth
- saveClientId string = "yes"
- // searching
- promptLength, searchLength, searchOffset int = 5, 10, 0
- searchNsfw bool = false
- // lists
- listOffset, listLength int = 0, 15
- listIncludeNsfw bool = false
+ // // auth
+ // saveClientId string = "yes"
+ // // searching
+ // promptLength, searchLength, searchOffset int = 5, 10, 0
+ // searchNsfw bool = false
+ // // lists
+ // listOffset, listLength int = 0, 15
+ // listIncludeNsfw bool = false
)
var rootCmd = &cobra.Command{
@@ -46,12 +46,16 @@ var rootCmd = &cobra.Command{
Long: "macli is an unofficial MyAnimeList Client for use inside the terminal.",
}
-func Execute() {
+func init() {
+ cobra.OnInitialize(initConfig)
+}
+
+func initConfig() {
viper.SetConfigName("macli")
- viper.SetConfigType("yaml")
+ //viper.SetConfigType("yaml")
viper.AddConfigPath(".")
- viper.AddConfigPath("$HOME/.config/macli")
- viper.AddConfigPath("/etc/macli")
+ // viper.AddConfigPath("$HOME/.config/macli")
+ // viper.AddConfigPath("/etc/macli")
// dont show error if file not found
// macli doesnt need a config file to work properly
@@ -64,6 +68,19 @@ func Execute() {
}
}
+ viper.SetDefault("searching.prompt_length", 5)
+ viper.SetDefault("searching.search_length", 10)
+ viper.SetDefault("searching.search_offset", 0)
+ viper.SetDefault("searching.search_nsfw", false)
+
+ viper.SetDefault("lists.list_offset", 0)
+ viper.SetDefault("lists.list_length", 15)
+ viper.SetDefault("lists.include_nsfw_results", false)
+
+ viper.SetDefault("auth.save_client_id", "yes")
+}
+
+func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)