💾
This commit is contained in:
@ -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")
|
||||
|
@ -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")
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
}
|
||||
|
62
cmd/repo.go
62
cmd/repo.go
@ -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")
|
||||
|
||||
}
|
||||
|
30
cmd/root.go
30
cmd/root.go
@ -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() + "?")
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user