Make vars syntax jive with typical ENV var syntax.
This commit is contained in:
@ -30,7 +30,7 @@ func searchRepos(uid, query, limit string) ([]*gogs.Repository, error) {
|
||||
client := &http.Client{}
|
||||
path := "/api/v1/repos/search?q=" + query + "&uid=" + uid + "&limit=" + limit
|
||||
|
||||
repos, err := getParsedResponse(client, "GET", viper.GetString("api_url")+path, nil, nil)
|
||||
repos, err := getParsedResponse(client, "GET", viper.GetString("GOGS_URL")+path, nil, nil)
|
||||
|
||||
return repos, err
|
||||
}
|
||||
|
12
cmd/root.go
12
cmd/root.go
@ -38,14 +38,14 @@ There's an example .go-gogs-cli.yaml`,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
token := viper.GetString("token")
|
||||
token := viper.GetString("GOGS_TOKEN")
|
||||
if token != "" {
|
||||
fmt.Println("Token authentication enabled.")
|
||||
} else {
|
||||
fmt.Println("No token found.")
|
||||
}
|
||||
|
||||
url := viper.GetString("api_url")
|
||||
url := viper.GetString("GOGS_URL")
|
||||
if url != "" {
|
||||
fmt.Println("Using API url @ ", url)
|
||||
} else {
|
||||
@ -71,8 +71,8 @@ func init() {
|
||||
// will be global for your application.
|
||||
|
||||
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gogs-cli.yaml)")
|
||||
RootCmd.PersistentFlags().StringVar(&apiURL, "url", viper.GetString("api_url"), "api url should include /api/v1 path (default is try.gogs.io/api/v1)")
|
||||
RootCmd.PersistentFlags().StringVar(&tokenArg, "token", viper.GetString("token"), "token authorization (if not specified in cfg file)")
|
||||
RootCmd.PersistentFlags().StringVar(&apiURL, "url", viper.GetString("GOGS_URL"), "api url should include /api/v1 path (default is try.gogs.io/api/v1)")
|
||||
RootCmd.PersistentFlags().StringVar(&tokenArg, "token", viper.GetString("GOGS_TOKEN"), "token authorization (if not specified in cfg file)")
|
||||
|
||||
// Cobra also supports local flags, which will only run
|
||||
// when this action is called directly.
|
||||
@ -85,8 +85,8 @@ func GetClient() *gogs.Client {
|
||||
}
|
||||
|
||||
func initClient() {
|
||||
url := viper.GetString("api_url")
|
||||
token := viper.GetString("token")
|
||||
url := viper.GetString("GOGS_URL")
|
||||
token := viper.GetString("GOGS_TOKEN")
|
||||
client = gogs.NewClient(url, token)
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ func getResponse(client *http.Client, method, url string, header http.Header, bo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Authorization", "token "+viper.GetString("token"))
|
||||
req.Header.Set("Authorization", "token "+viper.GetString("GOGS_TOKEN"))
|
||||
for k, v := range header {
|
||||
req.Header[k] = v
|
||||
}
|
||||
|
Reference in New Issue
Block a user