gogs-cli/README.md

153 lines
6.4 KiB
Markdown
Raw Normal View History

2016-07-27 17:58:17 +00:00
# Gogs CLI
2016-07-28 00:12:50 +00:00
Accesses the [Gogs Client API](https://github.com/gogits/go-gogs-client), which is currently available exclusively on [Gogs' `develop` branch](https://github.com/gogits/gogs/tree/develop).
2016-07-27 17:58:17 +00:00
2016-07-28 00:11:57 +00:00
> [Cobra](https://github.com/spf13/cobra) & [Viper](https://github.com/spf13/viper) go packages handle the hard work for the CLI interface.
2016-07-27 17:58:17 +00:00
2016-07-28 00:11:57 +00:00
## Setup.
2016-07-28 14:07:47 +00:00
2016-07-28 14:16:20 +00:00
_TLDR:_ Just make sure the `gogs` executable winds up somewhere in your `$PATH`. Set your `GOGS_URL` and `GOGS_TOKEN` vars somehow.
2016-07-28 14:07:47 +00:00
<br>
<br>
2016-07-29 15:12:55 +00:00
Clone the repo and build and install it yourself, or `go get github.com/irstacks/go-gogs-cli`.
2016-07-27 17:58:17 +00:00
2016-07-29 15:12:55 +00:00
Oh, _but how do you build it?_, you ask? _What path?_ you ask?
2016-07-27 17:58:17 +00:00
2016-07-29 15:12:55 +00:00
Ok, fine. Here's what's up. From the beginning.
2016-07-27 17:58:17 +00:00
2016-07-28 00:11:57 +00:00
With the marvelous `go get`...
```bash
$ go get github.com/irstacks/go-gogs-cli
$ cd $GOPATH/src/irstacks/go-gogs-cli
2016-07-28 00:20:15 +00:00
$ go get ./...
2016-07-28 00:11:57 +00:00
```
2016-07-28 14:07:47 +00:00
<br>
<br>
__Or__, with the almost-as-marvelous `git clone`...
2016-07-28 00:20:15 +00:00
```bash
2016-07-28 00:11:57 +00:00
$ cd where/i/like/to/put/funky/things
$ git clone https://github.com/irstacks/go-gogs-cli.git
2016-07-28 00:20:15 +00:00
# Pedantry explained immediately below...
$ go get stuff
$ go get morestuff
2016-07-28 00:11:57 +00:00
```
2016-07-29 15:12:55 +00:00
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.
2016-07-28 00:20:15 +00:00
<br>
<br>
Finally, we can build the sucker (this is __optional__ -- the repo comes with a build `gogs`).
2016-07-27 17:58:17 +00:00
```bash
2016-07-29 15:12:55 +00:00
$ go build -o gogs # Building it yourself will make sure the executable fits your OS and architecture.
2016-07-28 00:20:15 +00:00
```
2016-07-29 15:12:55 +00:00
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 ...`
2016-07-28 00:11:57 +00:00
2016-07-28 00:20:15 +00:00
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/`
<br>
... If you follow in my footsteps, make sure somewhere in your bash/fish/zsh shell you've added $HOME/bin (NO SECOND SLASH, you slashing fiend you) to your $PATH, with something like `export $PATH="$PATH:$HOME/bin"`.
```bash
2016-07-28 00:11:57 +00:00
$ cp gogs ~/bin/
2016-07-27 17:58:17 +00:00
```
2016-07-28 14:16:20 +00:00
... Or let Go decide where to put the executable for you. Just make sure your `$GOPATH/bin` is actually in your `$PATH`.
```bash
2016-07-29 15:12:55 +00:00
# This builds and moves the executable to $GOPATH/bin.
2016-07-28 14:16:20 +00:00
$ go install # From inside the base of the project.
```
2016-07-28 11:05:34 +00:00
<br>
2016-07-27 17:58:17 +00:00
2016-07-29 15:12:55 +00:00
#### This repo's build is for darwin (Mac).
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.
2016-07-29 15:12:55 +00:00
Once you've got the project, you'll need to configure your own `GOGS_TOKEN` and `GOGS_URL` variables.
<br>
2016-07-28 14:16:20 +00:00
You can use 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
```
2016-07-29 15:12:55 +00:00
Make that file (there's an example in the repo) and fill that in for your own self.
<br>
<br>
2016-07-29 15:12:55 +00:00
__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
```
2016-07-28 00:11:57 +00:00
## Usage.
2016-07-28 11:05:34 +00:00
So far, you can do things. What's that? You can _do things_? Yep! Do things!
2016-08-03 22:27:41 +00:00
```shell
2016-07-29 15:12:55 +00:00
# Create basic:
2016-07-28 13:24:51 +00:00
$ gogs repo create wheres-waldo # Create a repo owned by you.
2016-07-29 15:12:55 +00:00
# Create fancy:
$ gogs repo create Gophers/wheres-waldo --desc='awesome stuff' --private
2016-07-28 13:24:51 +00:00
$ gogs repo create where-waldo -r origin
2016-07-29 15:12:55 +00:00
# [Aliases] for create.
2016-07-28 13:24:51 +00:00
$ gogs repo [create|new|c|n]
2016-08-03 22:26:29 +00:00
# [Options] for create.
# [-d | --desc] # Description
# [-p | --private] # Make repo private
# [-r | --add-remote] # Add newly created gogs repo as a remote to your current git dir, initalizing git if necessary
2016-08-03 22:24:11 +00:00
```
2016-08-03 22:27:41 +00:00
```shell
2016-08-03 22:16:06 +00:00
# Migrate:
$ gogs repo migrate <myusername or my org's username>/mirror-mirror https://github.com/gogits/gogs.git
2016-08-03 22:24:11 +00:00
# [Aliases] for migrate
$ gogs repo [migrate|m]
2016-08-03 22:26:29 +00:00
# [Options] for migrate
# [-m | --mirror] # Make it a mirror of the original.
# [-p | --private] # Make it private.
2016-08-03 22:24:11 +00:00
```
2016-08-03 22:27:41 +00:00
```shell
2016-07-28 13:36:03 +00:00
# List basic:
2016-07-28 13:24:51 +00:00
$ gogs repo list # Get all yo repos.
2016-08-03 22:24:11 +00:00
# [Aliases]
$ gogs repo [list|l]
```
2016-08-03 22:27:41 +00:00
```shell
2016-07-28 13:36:03 +00:00
# Search basic:
$ gogs repo search waldo # Search public repos for keyword 'waldo'.
# Search fancy:
$ gogs repo search waldo --limit 1 --user thatguy
2016-07-28 13:24:51 +00:00
# [Aliases] for search.
$ gogs repo [search|find|s|f]
2016-08-03 22:26:29 +00:00
# [Options] for search.
# [-l | --limit] # Limit results
# [-u | --user] # By user, required if you want to search private repos
2016-08-03 22:24:11 +00:00
```
2016-08-03 22:27:41 +00:00
```shell
2016-07-29 15:12:55 +00:00
# Destroy basic:
2016-07-28 00:11:57 +00:00
$ gogs repo destroy irstacks my-exterminable-repo
$ gogs repo destroy irstacks/my-other-exterminable-repo
2016-07-28 13:24:51 +00:00
# [Aliases] for destroy.
$ gogs repo [destroy|delete|d|rid]
2016-08-03 22:24:11 +00:00
```
2016-08-03 22:27:41 +00:00
```shell
2016-07-28 13:36:03 +00:00
# Help?!
# Add --help after any command to see what's up, ie.
$ gogs --help
$ gogs repo --help
$ gogs repo create --help
# and so on...
2016-07-28 00:11:57 +00:00
```
2016-07-28 11:05:34 +00:00
<br>
<br>
__Oh, you're hot shit and use n > 1 Gogs?__ _Sweet_.
2016-07-29 15:12:55 +00:00
<br>
2016-07-28 11:05:34 +00:00
You can override your api and token by flagging a config file with the `--config` flag (like such)
```bash
$ gogs --config="$HOME/sneaky/place/.go-gogs-cli.yaml" repo create newjunk
```
<br>
or, override your api url and token individually on the fly with flags `--token` and `--url` for any command, like so:
```bash
$ gogs --url=http://some.other.company --token=qo23ransdlfknaw3oijr2323rasldf repo search waldo
```
2016-07-28 00:11:57 +00:00
2016-07-28 11:05:34 +00:00
<br>
<br>
2016-07-29 15:12:55 +00:00
You may have noticed that we're pretty heavy on the `gogs repo` and pretty light on the `gogs somethingelse` side of things. The [Gogs Client API](https://github.com/gogits/go-gogs-client) makes a bunch of endpoints and methods accessible for Users, Organizations, Issues, Admins, and so forth (although it's still very much a work in progress). Myself, I mostly just want to be able to create, search, and destroy like a fiend. If you would :heart: something and are unable to help yourself, let me know by opening an issue.
2016-07-28 00:23:11 +00:00
2016-07-28 00:11:57 +00:00
## Help out.
2016-07-28 11:05:34 +00:00
:clap: [chanting] Do it! Do it! Do it!