-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added strategy support, sources are now enabled per instance
- Loading branch information
Showing
20 changed files
with
414 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
homedir "github.com/mitchellh/go-homedir" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func initConfig(cfg *config, rootCmd *cobra.Command) { | ||
viper.SetDefault("sources", "cheatsh,learnxiny,tldr") | ||
|
||
viper.SetConfigName("radium") | ||
viper.AddConfigPath("./") | ||
if hd, err := homedir.Dir(); err == nil { | ||
viper.AddConfigPath(hd) | ||
} | ||
viper.AutomaticEnv() | ||
viper.BindPFlags(rootCmd.PersistentFlags()) | ||
|
||
viper.ReadInConfig() | ||
if err := viper.Unmarshal(cfg); err != nil { | ||
log.Fatalf("config err: %s\n", err) | ||
} | ||
} | ||
|
||
// config struct is used to store CLI configurations. configuration | ||
// values are read into this struct using viper | ||
type config struct { | ||
Sources []string `json:"sources"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/shivylp/radium" | ||
"github.com/shivylp/radium/sources" | ||
) | ||
|
||
func getNewRadiumInstance() *radium.Instance { | ||
func getNewRadiumInstance(cfg config) *radium.Instance { | ||
ins := radium.New(nil, nil) | ||
|
||
ins.RegisterSource("cheat.sh", sources.NewCheatSh()) | ||
ins.RegisterSource("tldr", sources.NewTLDR()) | ||
ins.RegisterSource("learnxinyminutes", sources.NewLearnXInYMins()) | ||
for _, src := range cfg.Sources { | ||
switch strings.ToLower(strings.TrimSpace(src)) { | ||
case "cheatsh", "cheat.sh": | ||
ins.RegisterSource("cheat.sh", sources.NewCheatSh()) | ||
case "learnxiny", "lxy", "learnxinyminutes": | ||
ins.RegisterSource("learnxinyminutes", sources.NewLearnXInYMins()) | ||
case "tldr": | ||
ins.RegisterSource("tldr", sources.NewTLDR()) | ||
case "wiki", "wikipedia": | ||
ins.RegisterSource("wikipedia", sources.NewWikipedia()) | ||
default: | ||
ins.Fatalf("unknown source type: %s", src) | ||
} | ||
} | ||
|
||
return ins | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.