This commit is contained in:
Mr. Is 2016-07-27 20:11:57 -04:00
parent 7ed05d13dc
commit 560eae6308
9 changed files with 111 additions and 142 deletions

View File

@ -1,29 +1,52 @@
# Gogs CLI
Accesses the [Gogs Client API](https://github.com/gogits/go-gogs-client), currently available on [Gogs' `develop` branch](https://github.com/gogits/gogs/tree/develop).
[Cobra](https://github.com/spf13/cobra) & [Viper](https://github.com/spf13/viper) go packages handle the hard work for the CLI interface.
> [Cobra](https://github.com/spf13/cobra) & [Viper](https://github.com/spf13/viper) go packages handle the hard work for the CLI interface.
Very much still a __work in progress__. That's in bold.
Very much still a __work in progress__. That's in bold.
## Setup
## 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 it yourself, or `go get github.com/irstacks/gogs-cli`.
Oh, _but how do you build it?_, you ask? _What path?_ you ask?
Make sure the `gogs` executable is available somewhere in your `$PATH`.
This repo's build is for darwin. You can build for linux with the nifty `env GOOS=linux go build -o gogs`.
## Usage
So far...
Here's what's up. From the beginning.
With the marvelous `go get`...
```bash
$ gogs repo # index all your repos
$ gogs repo -n my-new-repo
$ gogs repo -o anorganizationiown -n my-new-repo
$ go get github.com/irstacks/go-gogs-cli
$ cd $GOPATH/src/irstacks/go-gogs-cli
```
## Help out
With the almost-as-marvelous `git clone`...
```
$ cd where/i/like/to/put/funky/things
$ git clone https://github.com/irstacks/go-gogs-cli.git
```
Pull request at will.
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 location outside my $GOPATH (in part because I have so many esoteric locations and don't want to haggle with forever adjusting/amending my $GOPATH extension), 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.
```bash
$ go get ./... # Make sure we've got all the dependencies we need available.
$ 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 ...
# 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/
# ... 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".
$ 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 Window too but I don't trouble myself with such things.
## Usage.
So far, you can do things like...
```bash
$ gogs repo create my-new-repo --desc 'awesome stuff' --private --org GophersGophering # optional flag [-n|--name] if you want to be very particular
$ gogs repo new my-new-repo # new is an alias for create
$ gogs repo list # get all yo repos
$ gogs repo destroy irstacks my-exterminable-repo
$ gogs repo destroy irstacks/my-other-exterminable-repo
```
## Help out.
Please do!

View File

@ -1,17 +1,3 @@
// Copyright © 2016 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
@ -28,9 +14,16 @@ var repoIsPrivate bool
var orgName string
var createCmd = &cobra.Command{
Use: "create [my-new-repo | [-n | --name]] [-d | --desc] [-org | --org] [-p | --private]]",
Short: "Create a repository",
Long: `Create a repository for you or your organization.`,
Aliases: []string{"new"},
Use: "create",
Short: "Create a repository",
Long: `create [my-new-repo | [-n | --name]] [-d | --desc] [-org | --org] [-p | --private]]
$ gogs repo create my-new-repo
$ gogs repo new my-new-repo
$ gogs repo create -n=my-new-repo
$ gogs repo create my-new-repo --desc="a thing with things" --org=JustUsGuys -p=true
$ gogs repo new my-new-repo --private`,
Run: func(cmd *cobra.Command, args []string) {
// accept gogs repo create thingeys || gogs repo create -name=thingeys
@ -66,15 +59,6 @@ var createCmd = &cobra.Command{
func init() {
repoCmd.AddCommand(createCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// createCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// createCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
createCmd.Flags().StringVarP(&repoName, "name", "n", "", "repo name")
createCmd.Flags().StringVarP(&repoDescription, "desc", "d", "", "repo description")
createCmd.Flags().BoolVarP(&repoIsPrivate, "private", "p", false, "repo is private")

View File

@ -1,17 +1,3 @@
// Copyright © 2016 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
@ -23,9 +9,17 @@ import (
// destroyCmd represents the destroy command
var destroyCmd = &cobra.Command{
Use: "destroy [username/repo-name]",
Short: "Destroy a given repo.",
Long: `Destroy a repo by username/repo-name. CAREFUL! You won't be asked twice.`,
Use: "destroy [username repo-name | username/repo-name]",
Short: "Destroy a repo.",
Long: `destroy [username repo-name | username/repo-name]
$ destroy ia tester-repo
$ destroy ia/tester-repo
**CAREFUL!** YOU WON'T BE ASKED TWICE.
YE BE WARNED.
`,
Run: func(cmd *cobra.Command, args []string) {
var owner string
@ -70,15 +64,4 @@ var destroyCmd = &cobra.Command{
func init() {
repoCmd.AddCommand(destroyCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// destroyCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// destroyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -1,17 +1,3 @@
// Copyright © 2016 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
@ -39,17 +25,4 @@ var listCmd = &cobra.Command{
func init() {
repoCmd.AddCommand(listCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
//
// TODO
}

View File

@ -1,17 +1,3 @@
// Copyright © 2016 NAME HERE <EMAIL ADDRESS>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cmd
import (
@ -24,34 +10,42 @@ import (
// repoCmd represents the repo command
var repoCmd = &cobra.Command{
Use: "repo",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Short: "parent command for repositories",
Long: `gogs repo [(new|create)|list|destroy]
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
$ gogs repo new my-new-repo --private
$ gogs repo create my-new-repo --org=JustUsGuys
$ gogs repo list
$ gogs repo destroy ia my-new-repo
$ gogs repo destroy ia/my-new-repo
`,
Run: func(cmd *cobra.Command, args []string) {
// TODO: Work your own magic here
fmt.Println("repo called")
fmt.Println("Please use: gogs repo [(new|create)|list|destroy]")
},
}
func printRepo(repo *gogs.Repository) {
fmt.Printf("Name: %v\nGit url: %v\n\n", repo.FullName, repo.CloneUrl)
fmt.Println("------------------------------------------------")
fmt.Printf("* %v", repo.FullName)
if repo.Private {
fmt.Printf(" (private)")
}
if repo.Fork {
fmt.Printf(" (fork)")
}
fmt.Println()
if repo.Description != "" {
fmt.Println("[--> ", repo.Description)
}
fmt.Println("Go there: ", repo.HtmlUrl)
fmt.Println("SSH: ", repo.SshUrl)
fmt.Println("Clone it: ", repo.CloneUrl)
fmt.Println("------------------------------------------------")
}
func init() {
RootCmd.AddCommand(repoCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// repoCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// repoCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -34,15 +34,27 @@ var RootCmd = &cobra.Command{
Short: "Connect to the Gogs API.",
Long: `Welcome to the Gogs CLI.
You'll probably want a token for interacting with private data.
Visit your profile settings on Gogs and create a token, then stick it into
$HOME/.gogs-cli.yaml. While you're there you can adjust the default to your liking, too.`,
You'll probably, almost certainly, want a token for interacting with private data.
Visit your Profile Settings on Gogs and *create a token*.
You'll stick that into the default config file named below,
where you'll also want to *set your base Gogs url*.
$HOME/.go-gogs-cli.yaml
Recap:
- get a token from the Gogs UI Profile/settings page.
- put the token into the config file name above, along with
- the base url for your Gogs instance.
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")
if token != "" {
fmt.Println("Token authentication enabled @ ", token)
fmt.Println("Token authentication enabled.")
} else {
fmt.Println("No token found.")
}
@ -98,16 +110,16 @@ func initConfig() {
viper.SetConfigFile(cfgFile)
}
viper.SetConfigName(".gogs-cli") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
viper.AutomaticEnv() // read in environment variables that match
viper.SetConfigName(".go-gogs-cli") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
viper.AutomaticEnv() // read in environment variables that match
// viper.SetDefault("api_url", "try.gogs.io/api/v1")
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
// fmt.Println("Using config file:", viper.ConfigFileUsed())
} else {
fmt.Println("No configuration file found.")
fmt.Println("No configuration file found. Is there for sure one at " + viper.ConfigFileUsed() + "?")
}
}

BIN
gogs

Binary file not shown.

View File

@ -14,7 +14,7 @@
package main
import "github.com/irstacks/gogs-cli/cmd"
import "github.com/irstacks/go-gogs-cli/cmd"
func main() {
cmd.Execute()