Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
feat(help): Add 'repo' help pages
Browse files Browse the repository at this point in the history
  • Loading branch information
BreD1810 committed Aug 8, 2020
1 parent fd0d7d4 commit 8cf3baa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
39 changes: 0 additions & 39 deletions cmd/glab/utils/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,3 @@ FEEDBACK
Built with ❤ by Clement Sam <https://clementsam.tech>`)

}

//RepoHelp print help
func RepoHelp(message string) {

fmt.Println(message, `
USAGE
glab repo clone <owner/repo> [<dir>] [<options>] [<flags>]
OPTIONS
format: clone the repository as archive ,use values [zip,tar]
FLAGS
--help Show help for command
--version Show glab version
EXAMPLES
$ glab repo clone profclems/glab mydrirectory
ENVIRONMENT VARIABLES
GITLAB_TOKEN: an authentication token for API requests. Setting this avoids being
prompted to authenticate and overrides any previously stored credentials.
GITLAB_REPO: specify the Gitlab repository in "OWNER/REPO" format for commands that
otherwise operate on a local repository.
GITLAB_URI: specify the url of the gitlab server if self hosted (eg: gitlab.example.com)
LEARN MORE
Use "glab <command> <subcommand> --help" for more information about a command.
Read the manual at https://glab.clementsam.tech
FEEDBACK
Open an issue using “glab issue create -R profclems/glab”
Built with ❤ by Clement Sam <https://clementsam.tech>`)

}
30 changes: 26 additions & 4 deletions cmd/glab/utils/repo.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
package utils

import "fmt"
import (
"fmt"
"os"
"text/tabwriter"
)

// PrintHelpRepo : display repo help
// PrintHelpRepo : display repo command help
func PrintHelpRepo() {
tabWriter := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
defer tabWriter.Flush()
fmt.Println("USAGE")
fmt.Println(" glab repo <subcommand> [flags]")
fmt.Println()
fmt.Println("SUBCOMMANDS")
fmt.Fprintf(tabWriter, " %s:\t%s\n", "clone", "Clone a repository")
}

fmt.Println(`Repo Help`)

// PrintHelpRepoClone : display repo clone command help
func PrintHelpRepoClone() {
tabWriter := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
defer tabWriter.Flush()
fmt.Println("Clone a repository")
fmt.Println()
fmt.Println("USAGE")
fmt.Println(" glab repo clone <owner/repo> [<dir>] [<format>]")
fmt.Println()
fmt.Println("OPTIONS")
fmt.Fprintf(tabWriter, " %s:\t%s\n", "dir", `The directory to save the repository to`)
fmt.Fprintf(tabWriter, " %s:\t%s\n", "format", `Clone the repository as an archive. Valid options: "tar.gz", "tar.bz2", "tbz", "tbz2", "tb2", "bz2", "tar", "zip"`)
}
11 changes: 9 additions & 2 deletions commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func archiveRepo(repository string, format string, name string) {
extensions := []string{"tar.gz", "tar.bz2", "tbz", "tbz2", "tb2", "bz2", "tar", "zip"}
if b := contains(extensions, format); !b {

utils.RepoHelp("fatal: --format must be one of " + strings.Join(extensions[:], ","))
fmt.Println("fatal: --format must be one of " + strings.Join(extensions[:], ","))

return
}
Expand Down Expand Up @@ -101,7 +101,7 @@ func cloneRepo(cmdOptions map[string]string, cmdArgs map[int]string) {

if len(strings.TrimSpace(repo)) == 0 || !strings.Contains(repo, "/") {

utils.RepoHelp("fatal: You must specify a owner/repository to clone.")
fmt.Println("fatal: You must specify a owner/repository to clone.")

return
}
Expand Down Expand Up @@ -131,6 +131,13 @@ func ExecRepo(cmdArgs map[string]string, arrCmd map[int]string) {
"clone": cloneRepo,
}
if _, ok := commandList[arrCmd[0]]; ok {
if cmdArgs["help"] == "true" {
repoHelpList := map[string]func(){
"clone": utils.PrintHelpRepoClone,
}
repoHelpList[arrCmd[0]]()
return
}
commandList[arrCmd[0]](cmdArgs, arrCmd)
} else {
fmt.Println(arrCmd[0]+":", "Invalid Command")
Expand Down

0 comments on commit 8cf3baa

Please sign in to comment.