From 9627024bbc6864821cab213591e8f8006a75880f Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Sun, 3 Nov 2019 23:21:10 +0800 Subject: [PATCH] Minor improvements to command-line language Signed-off-by: Ambrose Chua --- cmd/config.go | 12 ++++++------ cmd/flags.go | 12 ++++++------ cmd/issues.go | 4 ++-- cmd/labels.go | 16 ++++++++-------- cmd/log.go | 2 -- cmd/login.go | 29 +++++++++++++---------------- cmd/logout.go | 8 ++++---- cmd/pulls.go | 4 ++-- cmd/releases.go | 22 +++++++++++----------- 9 files changed, 52 insertions(+), 57 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 3435196..255ebeb 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -84,7 +84,7 @@ func init() { dir := filepath.Join(homeDir, ".tea") err = os.MkdirAll(dir, os.ModePerm) 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") @@ -126,7 +126,7 @@ func addLogin(login Login) error { if l.URL == login.URL && l.Token == login.Token { 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 { return errors.New("URL has been added") @@ -155,7 +155,7 @@ func isFileExist(fileName string) (bool, error) { return false, err } 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 } @@ -198,7 +198,7 @@ func curGitRepoPath() (*Login, string, error) { // if no remote 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 @@ -219,7 +219,7 @@ func curGitRepoPath() (*Login, string, error) { remoteConfig, ok := gitConfig.Remotes[remoteValue] 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 { @@ -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") } diff --git a/cmd/flags.go b/cmd/flags.go index dded065..a74f335 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -22,28 +22,28 @@ var ( // LoginFlag provides flag to specify tea login profile var LoginFlag = cli.StringFlag{ Name: "login, l", - Usage: "Indicate one login, optional when inside a gitea repository", + Usage: "Use a different Gitea login. Optional", Destination: &loginValue, } // RepoFlag provides flag to specify repository var RepoFlag = cli.StringFlag{ Name: "repo, r", - Usage: "Indicate one repository, optional when inside a gitea repository", + Usage: "Repository to interact with. Optional", Destination: &repoValue, } // RemoteFlag provides flag to specify remote repository var RemoteFlag = cli.StringFlag{ 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, } // OutputFlag provides flag to specify output type var OutputFlag = cli.StringFlag{ Name: "output, o", - Usage: "Specify output format. (csv, simple, table, tsv, yaml)", + Usage: "Output format. (csv, simple, table, tsv, yaml)", Destination: &outputValue, } @@ -78,7 +78,7 @@ var AllDefaultFlags = append([]cli.Flag{ func initCommand() (*Login, string, string) { err := loadConfig(yamlConfigPath) if err != nil { - log.Fatal("load config file failed ", yamlConfigPath) + log.Fatal("Unable to load config file " + yamlConfigPath) } var login *Login @@ -90,7 +90,7 @@ func initCommand() (*Login, string, string) { } else { login = getLoginByName(loginValue) if login == nil { - log.Fatal("indicated login name ", loginValue, " does not exist") + log.Fatal("Login name " + loginValue + " does not exist") } } diff --git a/cmd/issues.go b/cmd/issues.go index fd37160..c70527a 100644 --- a/cmd/issues.go +++ b/cmd/issues.go @@ -19,8 +19,8 @@ import ( // CmdIssues represents to login a gitea server. var CmdIssues = cli.Command{ Name: "issues", - Usage: "Operate with issues of the repository", - Description: `Operate with issues of the repository`, + Usage: "List and create issues", + Description: `List and create issues`, Action: runIssues, Subcommands: []cli.Command{ CmdIssuesList, diff --git a/cmd/labels.go b/cmd/labels.go index b8ca81f..d9afbfc 100644 --- a/cmd/labels.go +++ b/cmd/labels.go @@ -20,8 +20,8 @@ import ( // CmdLabels represents to operate repositories' labels. var CmdLabels = cli.Command{ Name: "labels", - Usage: "Operate with labels of the repository", - Description: `Operate with labels of the repository`, + Usage: "Manage issue labels", + Description: `Manage issue labels`, Action: runLabels, Subcommands: []cli.Command{ CmdLabelCreate, @@ -90,8 +90,8 @@ func runLabels(ctx *cli.Context) error { // CmdLabelCreate represents a sub command of labels to create label. var CmdLabelCreate = cli.Command{ Name: "create", - Usage: "Create a label in repository", - Description: `Create a label in repository`, + Usage: "Create a label", + Description: `Create a label`, Action: runLabelCreate, Flags: []cli.Flag{ cli.StringFlag{ @@ -182,8 +182,8 @@ func runLabelCreate(ctx *cli.Context) error { // CmdLabelUpdate represents a sub command of labels to update label. var CmdLabelUpdate = cli.Command{ Name: "update", - Usage: "Update a label in repository", - Description: `Update a label in repository`, + Usage: "Update a label", + Description: `Update a label`, Action: runLabelUpdate, Flags: []cli.Flag{ cli.IntFlag{ @@ -242,8 +242,8 @@ func runLabelUpdate(ctx *cli.Context) error { // CmdLabelDelete represents a sub command of labels to delete label. var CmdLabelDelete = cli.Command{ Name: "delete", - Usage: "Delete a label in repository", - Description: `Delete a label in repository`, + Usage: "Delete a label", + Description: `Delete a label`, Action: runLabelCreate, Flags: []cli.Flag{ cli.IntFlag{ diff --git a/cmd/log.go b/cmd/log.go index dd3e6b8..13f12e8 100644 --- a/cmd/log.go +++ b/cmd/log.go @@ -17,8 +17,6 @@ var ( showLog bool ) -const outputUsage = "Specify output format - table (default), csv, simple, tsv or yaml." - // Println println content according the flag func Println(a ...interface{}) { if showLog { diff --git a/cmd/login.go b/cmd/login.go index 711124c..803a2aa 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -19,9 +19,8 @@ import ( // CmdLogin represents to login a gitea server. var CmdLogin = cli.Command{ Name: "login", - Usage: "Log in a Gitea server", - Description: `Log in a Gitea server`, - Action: runLoginList, + Usage: "Log in to a Gitea server", + Description: `Log in to a Gitea server`, Subcommands: []cli.Command{ cmdLoginList, cmdLoginAdd, @@ -31,28 +30,28 @@ var CmdLogin = cli.Command{ // CmdLogin represents to login a gitea server. var cmdLoginAdd = cli.Command{ Name: "add", - Usage: "Add a Login of a Gitea server", - Description: `Add a Login of a Gitea server`, + Usage: "Add a Gitea login", + Description: `Add a Gitea login`, Flags: []cli.Flag{ cli.StringFlag{ Name: "name, n", - Usage: "Name for the gitea login", + Usage: "Login name", }, cli.StringFlag{ Name: "url, u", Value: "https://try.gitea.io", EnvVar: "GITEA_SERVER_URL", - Usage: "Gitea server URL", + Usage: "Server URL", }, cli.StringFlag{ Name: "token, t", Value: "", EnvVar: "GITEA_SERVER_TOKEN", - Usage: "token for operating the Gitea login", + Usage: "Access token. Can be obtained from Settings > Applications", }, cli.BoolFlag{ Name: "insecure, i", - Usage: "insecure visit gitea server", + Usage: "Disable TLS verification", }, }, Action: runLoginAdd, @@ -62,18 +61,16 @@ func runLoginAdd(ctx *cli.Context) error { if !ctx.IsSet("url") { log.Fatal("You have to input Gitea server URL") } - if !ctx.IsSet("token") { log.Fatal("No token found") } - if !ctx.IsSet("name") { log.Fatal("You have to set a name for the login") } err := loadConfig(yamlConfigPath) 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")) @@ -92,7 +89,7 @@ func runLoginAdd(ctx *cli.Context) error { log.Fatal(err) } - fmt.Println("Login successful! Login name", u.UserName) + fmt.Println("Login successful! Login name " + u.UserName) err = addLogin(Login{ Name: ctx.String("name"), @@ -115,15 +112,15 @@ func runLoginAdd(ctx *cli.Context) error { // CmdLogin represents to login a gitea server. var cmdLoginList = cli.Command{ Name: "ls", - Usage: "List all Logins of Gitea servers", - Description: `List all Logins of Gitea servers`, + Usage: "List Gitea logins", + Description: `List Gitea logins`, Action: runLoginList, } func runLoginList(ctx *cli.Context) error { err := loadConfig(yamlConfigPath) if err != nil { - log.Fatal("load config file failed", yamlConfigPath) + log.Fatal("Unable to load config file " + yamlConfigPath) } fmt.Printf("Name\tURL\tSSHHost\n") diff --git a/cmd/logout.go b/cmd/logout.go index 9d5a573..e7eb3f7 100644 --- a/cmd/logout.go +++ b/cmd/logout.go @@ -21,7 +21,7 @@ var CmdLogout = cli.Command{ Flags: []cli.Flag{ cli.StringFlag{ 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") { name = ctx.String("name") } else { - return errors.New("need log out server name") + return errors.New("Please specify a login name") } err := loadConfig(yamlConfigPath) if err != nil { - log.Fatal("load config file failed", yamlConfigPath) + log.Fatal("Unable to load config file " + yamlConfigPath) } var idx = -1 @@ -52,7 +52,7 @@ func runLogout(ctx *cli.Context) error { config.Logins = append(config.Logins[:idx], config.Logins[idx+1:]...) err = saveConfig(yamlConfigPath) if err != nil { - log.Fatal("save config file failed", yamlConfigPath) + log.Fatal("Unable to save config file " + yamlConfigPath) } } diff --git a/cmd/pulls.go b/cmd/pulls.go index b688674..24e43de 100644 --- a/cmd/pulls.go +++ b/cmd/pulls.go @@ -16,8 +16,8 @@ import ( // CmdPulls represents to login a gitea server. var CmdPulls = cli.Command{ Name: "pulls", - Usage: "Operate with pulls of the repository", - Description: `Operate with pulls of the repository`, + Usage: "List open pull requests", + Description: `List open pull requests`, Action: runPulls, Flags: AllDefaultFlags, } diff --git a/cmd/releases.go b/cmd/releases.go index 60f24f1..c327d01 100644 --- a/cmd/releases.go +++ b/cmd/releases.go @@ -17,8 +17,8 @@ import ( // CmdReleases represents to login a gitea server. var CmdReleases = cli.Command{ Name: "releases", - Usage: "Operate with releases of the repository", - Description: `Operate with releases of the repository`, + Usage: "Create releases", + Description: `Create releases`, Action: runReleases, Subcommands: []cli.Command{ CmdReleaseCreate, @@ -67,37 +67,37 @@ func runReleases(ctx *cli.Context) error { // CmdReleaseCreate represents a sub command of Release to create release. var CmdReleaseCreate = cli.Command{ Name: "create", - Usage: "Create a release in repository", - Description: `Create a release in repository`, + Usage: "Create a release", + Description: `Create a release`, Action: runReleaseCreate, Flags: append([]cli.Flag{ cli.StringFlag{ Name: "tag", - Usage: "release tag name", + Usage: "Tag name", }, cli.StringFlag{ Name: "target", - Usage: "release target refs, branch name or commit id", + Usage: "Target refs, branch name or commit id", }, cli.StringFlag{ Name: "title, t", - Usage: "release title to create", + Usage: "Release title", }, cli.StringFlag{ Name: "note, n", - Usage: "release note to create", + Usage: "Release notes", }, cli.BoolFlag{ Name: "draft, d", - Usage: "the release is a draft", + Usage: "Is a draft", }, cli.BoolFlag{ Name: "prerelease, p", - Usage: "the release is a prerelease", + Usage: "Is a pre-release", }, cli.StringSliceFlag{ Name: "asset, a", - Usage: "a list of files to attach to the release", + Usage: "List of files to attach", }, }, LoginRepoFlags...), } -- 2.40.1