diff --git a/.go-gogs-cli.example.yaml b/.go-gogs-cli.example.yaml index ec698ae..376104c 100644 --- a/.go-gogs-cli.example.yaml +++ b/.go-gogs-cli.example.yaml @@ -1,5 +1,10 @@ # This file will by default live in $HOME/.go-gogs-cli.yaml. # You can put it anywhere else, too, but you'll need to tell go-gogs-cli # about it in cmd/root.go (down in initConfig). -token: 0e6709o05da4753dddf5f592074fdc263f02n801 -api_url: http://my.goggers.me +# +# Or, you can not use this file and instead set these as ENV variables, like +# export GOGS_TOKEN=qorudfjasij3290r23rkansfj23asdf +# export GOGS_URL=http://my.goggers.me +# +GOGS_TOKEN: 0e6709o05da4753dddf5f592074fdc263f02n801 +GOGS_URL: http://my.goggers.me diff --git a/README.md b/README.md index a3d783f..4881408 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Accesses the [Gogs Client API](https://github.com/gogits/go-gogs-client), which ## Setup. -Clone the repo and build it yourself, or `go get github.com/irstacks/go-gogs-cli`. Just make sure the `gogs` executable winds up somewhere in your `$PATH`. +Clone the repo and build and install it yourself, or `go get github.com/irstacks/go-gogs-cli`. Just make sure the `gogs` executable winds up somewhere in your `$PATH`. Oh, _but how do you build it?_, you ask? _What path?_ you ask? @@ -26,14 +26,14 @@ $ git clone https://github.com/irstacks/go-gogs-cli.git $ go get stuff $ go get morestuff ``` -Now, I say almost-as-marvelous because if you use `git clone` you may run into issues about your $GOPATH. It happens. Since I haven't figured out how to consistently `go get` all the dependencies I need for a given Go project from esoteric locations outside my $GOPATH (in part because I have so many esoteric locations and don't want to haggle with forever adjusting/amending my $GOPATH extensioners), I usually just wind up running `go run main.go` or `go build -o gogs` and `go get`ting the dependencies it complains about one-by-one. I know, it sucks. But that's just how I roll sometimes. +I say almost-as-marvelous because if you use `git clone` you may run into issues about your $GOPATH. It happens. Since I haven't figured out how to consistently `go get` all the dependencies I need for a given Go project from esoteric locations outside my $GOPATH (in part because I have so many esoteric locations and don't want to haggle with forever adjusting/amending my $GOPATH extensioners), I usually just wind up running `go run main.go` or `go build -o gogs` and `go get`ting the dependencies it complains about one-by-one. I know, it sucks. But that's just how I roll sometimes.

-Finally, we can build the sucker. +Finally, we can build the sucker (this is __optional__ -- the repo comes with a build `gogs`). ```bash $ go build -o gogs ``` -Here we're using -o to tell go where to build the build it makes, in this case a file in the same directory we're with the name 'gogs' (because thats a lot shorter than go-gogs-cli). Note that whatever you name this file it what it will be accessible for you as on the CLI. So if you name it 'goo' (awesome.), then your commands will be all like: `$ goo repo new ...` +Here we're using -o to tell go where to build the build it makes, in this case a file in the same directory we're with the name `gogs` (because thats a lot shorter than 'go-gogs-cli'). Note that whatever you name this file is what it will be accessible for you as on the CLI. So if you name it 'goo' (awesome.), then your commands will be all like: `$ goo repo new ...` Now here you've got some options (probably) about in which of your $PATH's paths you want to stick it. I like to keep my custom thingeys out of the dredges, so I stick mine in `$HOME/bin/`
@@ -44,7 +44,28 @@ $ cp gogs ~/bin/
#### This repo's build is for darwin (Mac). -You can build for linux with the nifty `env GOOS=linux go build -o gogs`. You can probably build for Windows too but I don't trouble myself with such things. +If you're on a Mac and want to build it for your server or something, you can build for linux with the nifty `env GOOS=linux go build -o gogs`. You can probably build for Windows too but I don't trouble myself with such things. + +## Config. +Once you've got the project, you'll need to configure your own `GOGS_TOKEN` and `GOGS_URL` variables. +
+You can use +```bash +$ go install # From inside the base of the project. +``` +which'll create a file called `.go-gogs-cli.yaml` that likes to live at `$HOME/.go-gogs-cli.yaml`. It handles configuring your __Gogs url__ and __token__, like such: +```yaml +GOGS_TOKEN: 0e6709o05da4753dddf5f592374fdc263f02n801 +GOGS_URL: http://my.goggers.me +``` +Fill that in for your own self. +
+
+__Or__, if you'd rather use environment variables, that'll work fine too. +```bash +export GOGS_TOKEN=asdlfj239r029fzsfasf923r23f +export GOGS_URL=http://my.goggers.me +``` ## Usage. So far, you can do things. What's that? You can _do things_? Yep! Do things! diff --git a/cmd/repo-search.go b/cmd/repo-search.go index cd096db..2a2841e 100644 --- a/cmd/repo-search.go +++ b/cmd/repo-search.go @@ -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 } diff --git a/cmd/root.go b/cmd/root.go index 7e9b92d..c343e37 100644 --- a/cmd/root.go +++ b/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) } diff --git a/cmd/util.go b/cmd/util.go index d554e0b..7172da8 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -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 } diff --git a/gogs b/gogs index 0dff844..c55159b 100755 Binary files a/gogs and b/gogs differ