mirror of
https://gitea.com/gitea/tea.git
synced 2024-11-25 12:01:36 +01:00
Minor improvements to command-line language (#66)
This commit is contained in:
parent
3d128cfc69
commit
72b602409b
@ -84,7 +84,7 @@ func init() {
|
|||||||
dir := filepath.Join(homeDir, ".tea")
|
dir := filepath.Join(homeDir, ".tea")
|
||||||
err = os.MkdirAll(dir, os.ModePerm)
|
err = os.MkdirAll(dir, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Init tea config dir", dir, "failed")
|
log.Fatal("Init tea config dir " + dir + " failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
yamlConfigPath = filepath.Join(dir, "tea.yml")
|
yamlConfigPath = filepath.Join(dir, "tea.yml")
|
||||||
@ -126,7 +126,7 @@ func addLogin(login Login) error {
|
|||||||
if l.URL == login.URL && l.Token == login.Token {
|
if l.URL == login.URL && l.Token == login.Token {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return errors.New("login name has already been used")
|
return errors.New("Login name has already been used")
|
||||||
}
|
}
|
||||||
if l.URL == login.URL && l.Token == login.Token {
|
if l.URL == login.URL && l.Token == login.Token {
|
||||||
return errors.New("URL has been added")
|
return errors.New("URL has been added")
|
||||||
@ -155,7 +155,7 @@ func isFileExist(fileName string) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
return false, errors.New("the same name directory exist")
|
return false, errors.New("A directory with the same name exists")
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ func curGitRepoPath() (*Login, string, error) {
|
|||||||
|
|
||||||
// if no remote
|
// if no remote
|
||||||
if len(gitConfig.Remotes) == 0 {
|
if len(gitConfig.Remotes) == 0 {
|
||||||
return nil, "", errors.New("No remote repository set on this git repository")
|
return nil, "", errors.New("No remote(s) found in this Git repository")
|
||||||
}
|
}
|
||||||
|
|
||||||
// if only one remote exists
|
// if only one remote exists
|
||||||
@ -219,7 +219,7 @@ func curGitRepoPath() (*Login, string, error) {
|
|||||||
|
|
||||||
remoteConfig, ok := gitConfig.Remotes[remoteValue]
|
remoteConfig, ok := gitConfig.Remotes[remoteValue]
|
||||||
if !ok || remoteConfig == nil {
|
if !ok || remoteConfig == nil {
|
||||||
return nil, "", errors.New("No remote " + remoteValue + " found on this git repository")
|
return nil, "", errors.New("Remote " + remoteValue + " not found in this Git repository")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, l := range config.Logins {
|
for _, l := range config.Logins {
|
||||||
@ -242,5 +242,5 @@ func curGitRepoPath() (*Login, string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, "", errors.New("No Gitea login found")
|
return nil, "", errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository")
|
||||||
}
|
}
|
||||||
|
12
cmd/flags.go
12
cmd/flags.go
@ -22,28 +22,28 @@ var (
|
|||||||
// LoginFlag provides flag to specify tea login profile
|
// LoginFlag provides flag to specify tea login profile
|
||||||
var LoginFlag = cli.StringFlag{
|
var LoginFlag = cli.StringFlag{
|
||||||
Name: "login, l",
|
Name: "login, l",
|
||||||
Usage: "Indicate one login, optional when inside a gitea repository",
|
Usage: "Use a different Gitea login. Optional",
|
||||||
Destination: &loginValue,
|
Destination: &loginValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepoFlag provides flag to specify repository
|
// RepoFlag provides flag to specify repository
|
||||||
var RepoFlag = cli.StringFlag{
|
var RepoFlag = cli.StringFlag{
|
||||||
Name: "repo, r",
|
Name: "repo, r",
|
||||||
Usage: "Indicate one repository, optional when inside a gitea repository",
|
Usage: "Repository to interact with. Optional",
|
||||||
Destination: &repoValue,
|
Destination: &repoValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteFlag provides flag to specify remote repository
|
// RemoteFlag provides flag to specify remote repository
|
||||||
var RemoteFlag = cli.StringFlag{
|
var RemoteFlag = cli.StringFlag{
|
||||||
Name: "remote, R",
|
Name: "remote, R",
|
||||||
Usage: "Set a specific remote repository, is optional if not set use git default one",
|
Usage: "Discover Gitea login from remote. Optional",
|
||||||
Destination: &remoteValue,
|
Destination: &remoteValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputFlag provides flag to specify output type
|
// OutputFlag provides flag to specify output type
|
||||||
var OutputFlag = cli.StringFlag{
|
var OutputFlag = cli.StringFlag{
|
||||||
Name: "output, o",
|
Name: "output, o",
|
||||||
Usage: "Specify output format. (csv, simple, table, tsv, yaml)",
|
Usage: "Output format. (csv, simple, table, tsv, yaml)",
|
||||||
Destination: &outputValue,
|
Destination: &outputValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ var AllDefaultFlags = append([]cli.Flag{
|
|||||||
func initCommand() (*Login, string, string) {
|
func initCommand() (*Login, string, string) {
|
||||||
err := loadConfig(yamlConfigPath)
|
err := loadConfig(yamlConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("load config file failed ", yamlConfigPath)
|
log.Fatal("Unable to load config file " + yamlConfigPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
var login *Login
|
var login *Login
|
||||||
@ -90,7 +90,7 @@ func initCommand() (*Login, string, string) {
|
|||||||
} else {
|
} else {
|
||||||
login = getLoginByName(loginValue)
|
login = getLoginByName(loginValue)
|
||||||
if login == nil {
|
if login == nil {
|
||||||
log.Fatal("indicated login name ", loginValue, " does not exist")
|
log.Fatal("Login name " + loginValue + " does not exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
// CmdIssues represents to login a gitea server.
|
// CmdIssues represents to login a gitea server.
|
||||||
var CmdIssues = cli.Command{
|
var CmdIssues = cli.Command{
|
||||||
Name: "issues",
|
Name: "issues",
|
||||||
Usage: "Operate with issues of the repository",
|
Usage: "List and create issues",
|
||||||
Description: `Operate with issues of the repository`,
|
Description: `List and create issues`,
|
||||||
Action: runIssues,
|
Action: runIssues,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
CmdIssuesList,
|
CmdIssuesList,
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
// CmdLabels represents to operate repositories' labels.
|
// CmdLabels represents to operate repositories' labels.
|
||||||
var CmdLabels = cli.Command{
|
var CmdLabels = cli.Command{
|
||||||
Name: "labels",
|
Name: "labels",
|
||||||
Usage: "Operate with labels of the repository",
|
Usage: "Manage issue labels",
|
||||||
Description: `Operate with labels of the repository`,
|
Description: `Manage issue labels`,
|
||||||
Action: runLabels,
|
Action: runLabels,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
CmdLabelCreate,
|
CmdLabelCreate,
|
||||||
@ -90,8 +90,8 @@ func runLabels(ctx *cli.Context) error {
|
|||||||
// CmdLabelCreate represents a sub command of labels to create label.
|
// CmdLabelCreate represents a sub command of labels to create label.
|
||||||
var CmdLabelCreate = cli.Command{
|
var CmdLabelCreate = cli.Command{
|
||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "Create a label in repository",
|
Usage: "Create a label",
|
||||||
Description: `Create a label in repository`,
|
Description: `Create a label`,
|
||||||
Action: runLabelCreate,
|
Action: runLabelCreate,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
@ -182,8 +182,8 @@ func runLabelCreate(ctx *cli.Context) error {
|
|||||||
// CmdLabelUpdate represents a sub command of labels to update label.
|
// CmdLabelUpdate represents a sub command of labels to update label.
|
||||||
var CmdLabelUpdate = cli.Command{
|
var CmdLabelUpdate = cli.Command{
|
||||||
Name: "update",
|
Name: "update",
|
||||||
Usage: "Update a label in repository",
|
Usage: "Update a label",
|
||||||
Description: `Update a label in repository`,
|
Description: `Update a label`,
|
||||||
Action: runLabelUpdate,
|
Action: runLabelUpdate,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
@ -242,8 +242,8 @@ func runLabelUpdate(ctx *cli.Context) error {
|
|||||||
// CmdLabelDelete represents a sub command of labels to delete label.
|
// CmdLabelDelete represents a sub command of labels to delete label.
|
||||||
var CmdLabelDelete = cli.Command{
|
var CmdLabelDelete = cli.Command{
|
||||||
Name: "delete",
|
Name: "delete",
|
||||||
Usage: "Delete a label in repository",
|
Usage: "Delete a label",
|
||||||
Description: `Delete a label in repository`,
|
Description: `Delete a label`,
|
||||||
Action: runLabelCreate,
|
Action: runLabelCreate,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
|
@ -17,8 +17,6 @@ var (
|
|||||||
showLog bool
|
showLog bool
|
||||||
)
|
)
|
||||||
|
|
||||||
const outputUsage = "Specify output format - table (default), csv, simple, tsv or yaml."
|
|
||||||
|
|
||||||
// Println println content according the flag
|
// Println println content according the flag
|
||||||
func Println(a ...interface{}) {
|
func Println(a ...interface{}) {
|
||||||
if showLog {
|
if showLog {
|
||||||
|
29
cmd/login.go
29
cmd/login.go
@ -19,9 +19,8 @@ import (
|
|||||||
// CmdLogin represents to login a gitea server.
|
// CmdLogin represents to login a gitea server.
|
||||||
var CmdLogin = cli.Command{
|
var CmdLogin = cli.Command{
|
||||||
Name: "login",
|
Name: "login",
|
||||||
Usage: "Log in a Gitea server",
|
Usage: "Log in to a Gitea server",
|
||||||
Description: `Log in a Gitea server`,
|
Description: `Log in to a Gitea server`,
|
||||||
Action: runLoginList,
|
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
cmdLoginList,
|
cmdLoginList,
|
||||||
cmdLoginAdd,
|
cmdLoginAdd,
|
||||||
@ -31,28 +30,28 @@ var CmdLogin = cli.Command{
|
|||||||
// CmdLogin represents to login a gitea server.
|
// CmdLogin represents to login a gitea server.
|
||||||
var cmdLoginAdd = cli.Command{
|
var cmdLoginAdd = cli.Command{
|
||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "Add a Login of a Gitea server",
|
Usage: "Add a Gitea login",
|
||||||
Description: `Add a Login of a Gitea server`,
|
Description: `Add a Gitea login`,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "Name for the gitea login",
|
Usage: "Login name",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "url, u",
|
Name: "url, u",
|
||||||
Value: "https://try.gitea.io",
|
Value: "https://try.gitea.io",
|
||||||
EnvVar: "GITEA_SERVER_URL",
|
EnvVar: "GITEA_SERVER_URL",
|
||||||
Usage: "Gitea server URL",
|
Usage: "Server URL",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "token, t",
|
Name: "token, t",
|
||||||
Value: "",
|
Value: "",
|
||||||
EnvVar: "GITEA_SERVER_TOKEN",
|
EnvVar: "GITEA_SERVER_TOKEN",
|
||||||
Usage: "token for operating the Gitea login",
|
Usage: "Access token. Can be obtained from Settings > Applications",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "insecure, i",
|
Name: "insecure, i",
|
||||||
Usage: "insecure visit gitea server",
|
Usage: "Disable TLS verification",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: runLoginAdd,
|
Action: runLoginAdd,
|
||||||
@ -62,18 +61,16 @@ func runLoginAdd(ctx *cli.Context) error {
|
|||||||
if !ctx.IsSet("url") {
|
if !ctx.IsSet("url") {
|
||||||
log.Fatal("You have to input Gitea server URL")
|
log.Fatal("You have to input Gitea server URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSet("token") {
|
if !ctx.IsSet("token") {
|
||||||
log.Fatal("No token found")
|
log.Fatal("No token found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ctx.IsSet("name") {
|
if !ctx.IsSet("name") {
|
||||||
log.Fatal("You have to set a name for the login")
|
log.Fatal("You have to set a name for the login")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := loadConfig(yamlConfigPath)
|
err := loadConfig(yamlConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("load config file failed", yamlConfigPath)
|
log.Fatal("Unable to load config file " + yamlConfigPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
client := gitea.NewClient(ctx.String("url"), ctx.String("token"))
|
client := gitea.NewClient(ctx.String("url"), ctx.String("token"))
|
||||||
@ -92,7 +89,7 @@ func runLoginAdd(ctx *cli.Context) error {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Login successful! Login name", u.UserName)
|
fmt.Println("Login successful! Login name " + u.UserName)
|
||||||
|
|
||||||
err = addLogin(Login{
|
err = addLogin(Login{
|
||||||
Name: ctx.String("name"),
|
Name: ctx.String("name"),
|
||||||
@ -115,15 +112,15 @@ func runLoginAdd(ctx *cli.Context) error {
|
|||||||
// CmdLogin represents to login a gitea server.
|
// CmdLogin represents to login a gitea server.
|
||||||
var cmdLoginList = cli.Command{
|
var cmdLoginList = cli.Command{
|
||||||
Name: "ls",
|
Name: "ls",
|
||||||
Usage: "List all Logins of Gitea servers",
|
Usage: "List Gitea logins",
|
||||||
Description: `List all Logins of Gitea servers`,
|
Description: `List Gitea logins`,
|
||||||
Action: runLoginList,
|
Action: runLoginList,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runLoginList(ctx *cli.Context) error {
|
func runLoginList(ctx *cli.Context) error {
|
||||||
err := loadConfig(yamlConfigPath)
|
err := loadConfig(yamlConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("load config file failed", yamlConfigPath)
|
log.Fatal("Unable to load config file " + yamlConfigPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Name\tURL\tSSHHost\n")
|
fmt.Printf("Name\tURL\tSSHHost\n")
|
||||||
|
@ -21,7 +21,7 @@ var CmdLogout = cli.Command{
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "name, n",
|
Name: "name, n",
|
||||||
Usage: "name wants to log out",
|
Usage: "Login name to remove",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -33,12 +33,12 @@ func runLogout(ctx *cli.Context) error {
|
|||||||
} else if ctx.IsSet("name") {
|
} else if ctx.IsSet("name") {
|
||||||
name = ctx.String("name")
|
name = ctx.String("name")
|
||||||
} else {
|
} else {
|
||||||
return errors.New("need log out server name")
|
return errors.New("Please specify a login name")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := loadConfig(yamlConfigPath)
|
err := loadConfig(yamlConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("load config file failed", yamlConfigPath)
|
log.Fatal("Unable to load config file " + yamlConfigPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
var idx = -1
|
var idx = -1
|
||||||
@ -52,7 +52,7 @@ func runLogout(ctx *cli.Context) error {
|
|||||||
config.Logins = append(config.Logins[:idx], config.Logins[idx+1:]...)
|
config.Logins = append(config.Logins[:idx], config.Logins[idx+1:]...)
|
||||||
err = saveConfig(yamlConfigPath)
|
err = saveConfig(yamlConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("save config file failed", yamlConfigPath)
|
log.Fatal("Unable to save config file " + yamlConfigPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
// CmdPulls represents to login a gitea server.
|
// CmdPulls represents to login a gitea server.
|
||||||
var CmdPulls = cli.Command{
|
var CmdPulls = cli.Command{
|
||||||
Name: "pulls",
|
Name: "pulls",
|
||||||
Usage: "Operate with pulls of the repository",
|
Usage: "List open pull requests",
|
||||||
Description: `Operate with pulls of the repository`,
|
Description: `List open pull requests`,
|
||||||
Action: runPulls,
|
Action: runPulls,
|
||||||
Flags: AllDefaultFlags,
|
Flags: AllDefaultFlags,
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ import (
|
|||||||
// CmdReleases represents to login a gitea server.
|
// CmdReleases represents to login a gitea server.
|
||||||
var CmdReleases = cli.Command{
|
var CmdReleases = cli.Command{
|
||||||
Name: "releases",
|
Name: "releases",
|
||||||
Usage: "Operate with releases of the repository",
|
Usage: "Create releases",
|
||||||
Description: `Operate with releases of the repository`,
|
Description: `Create releases`,
|
||||||
Action: runReleases,
|
Action: runReleases,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
CmdReleaseCreate,
|
CmdReleaseCreate,
|
||||||
@ -67,37 +67,37 @@ func runReleases(ctx *cli.Context) error {
|
|||||||
// CmdReleaseCreate represents a sub command of Release to create release.
|
// CmdReleaseCreate represents a sub command of Release to create release.
|
||||||
var CmdReleaseCreate = cli.Command{
|
var CmdReleaseCreate = cli.Command{
|
||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "Create a release in repository",
|
Usage: "Create a release",
|
||||||
Description: `Create a release in repository`,
|
Description: `Create a release`,
|
||||||
Action: runReleaseCreate,
|
Action: runReleaseCreate,
|
||||||
Flags: append([]cli.Flag{
|
Flags: append([]cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "tag",
|
Name: "tag",
|
||||||
Usage: "release tag name",
|
Usage: "Tag name",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "target",
|
Name: "target",
|
||||||
Usage: "release target refs, branch name or commit id",
|
Usage: "Target refs, branch name or commit id",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "title, t",
|
Name: "title, t",
|
||||||
Usage: "release title to create",
|
Usage: "Release title",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "note, n",
|
Name: "note, n",
|
||||||
Usage: "release note to create",
|
Usage: "Release notes",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "draft, d",
|
Name: "draft, d",
|
||||||
Usage: "the release is a draft",
|
Usage: "Is a draft",
|
||||||
},
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "prerelease, p",
|
Name: "prerelease, p",
|
||||||
Usage: "the release is a prerelease",
|
Usage: "Is a pre-release",
|
||||||
},
|
},
|
||||||
cli.StringSliceFlag{
|
cli.StringSliceFlag{
|
||||||
Name: "asset, a",
|
Name: "asset, a",
|
||||||
Usage: "a list of files to attach to the release",
|
Usage: "List of files to attach",
|
||||||
},
|
},
|
||||||
}, LoginRepoFlags...),
|
}, LoginRepoFlags...),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user