Merge branch 'trunk' of https://github.com/cli/cli into feature/repo-with-gitignore-license

This commit is contained in:
Gowtham Munukutla 2021-06-23 09:28:20 +05:30
commit 9ecbdb26c5
9 changed files with 68 additions and 38 deletions

View file

@ -197,3 +197,18 @@ jobs:
GIT_AUTHOR_NAME: cli automation
GIT_COMMITTER_EMAIL: noreply@github.com
GIT_AUTHOR_EMAIL: noreply@github.com
- name: Bump Winget manifest
shell: pwsh
env:
WINGETCREATE_VERSION: v0.2.0.29-preview
GITHUB_TOKEN: ${{ secrets.UPLOAD_GITHUB_TOKEN }}
run: |
$tagname = $env:GITHUB_REF.Replace("refs/tags/", "")
$version = $tagname.Replace("v", "")
$url = "https://github.com/cli/cli/releases/download/${tagname}/gh_${version}_windows_amd64.msi"
iwr https://github.com/microsoft/winget-create/releases/download/${env:WINGETCREATE_VERSION}/wingetcreate.exe -OutFile wingetcreate.exe
.\wingetcreate.exe update GitHub.cli --url $url --version $version
if ($version -notmatch "-") {
.\wingetcreate.exe submit .\manifests\g\GitHub\cli\${version}\ --token $env:GITHUB_TOKEN
}

View file

@ -159,11 +159,17 @@ func mainRun() exitCode {
cs := cmdFactory.IOStreams.ColorScheme()
if cmd != nil && cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
fmt.Fprintln(stderr, cs.Bold("Welcome to GitHub CLI!"))
fmt.Fprintln(stderr)
fmt.Fprintln(stderr, "To authenticate, please run `gh auth login`.")
return exitAuth
authError := errors.New("authError")
rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
// require that the user is authenticated before running most commands
if cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) {
fmt.Fprintln(stderr, cs.Bold("Welcome to GitHub CLI!"))
fmt.Fprintln(stderr)
fmt.Fprintln(stderr, "To authenticate, please run `gh auth login`.")
return authError
}
return nil
}
rootCmd.SetArgs(expandedArgs)
@ -177,6 +183,8 @@ func mainRun() exitCode {
fmt.Fprint(stderr, "\n")
}
return exitCancel
} else if errors.Is(err, authError) {
return exitAuth
}
printError(stderr, err, cmd, hasDebug)

View file

@ -9,39 +9,30 @@ import (
"github.com/spf13/cobra"
)
type ActionsOptions struct {
IO *iostreams.IOStreams
}
func NewCmdActions(f *cmdutil.Factory) *cobra.Command {
opts := ActionsOptions{
IO: f.IOStreams,
}
cs := f.IOStreams.ColorScheme()
cmd := &cobra.Command{
Use: "actions",
Short: "Learn about working with GitHub actions",
Long: actionsExplainer(nil),
Long: actionsExplainer(cs),
Run: func(cmd *cobra.Command, args []string) {
actionsRun(opts)
fmt.Fprintln(f.IOStreams.Out, actionsExplainer(cs))
},
Annotations: map[string]string{
"IsActions": "true",
},
}
cmdutil.DisableAuthCheck(cmd)
return cmd
}
func actionsExplainer(cs *iostreams.ColorScheme) string {
header := "Welcome to GitHub Actions on the command line."
runHeader := "Interacting with workflow runs"
workflowHeader := "Interacting with workflow files"
if cs != nil {
header = cs.Bold(header)
runHeader = cs.Bold(runHeader)
workflowHeader = cs.Bold(workflowHeader)
}
header := cs.Bold("Welcome to GitHub Actions on the command line.")
runHeader := cs.Bold("Interacting with workflow runs")
workflowHeader := cs.Bold("Interacting with workflow files")
return heredoc.Docf(`
%s
@ -70,8 +61,3 @@ func actionsExplainer(cs *iostreams.ColorScheme) string {
<https://docs.github.com/en/actions/guides/managing-github-actions-with-github-cli>
`, header, runHeader, workflowHeader)
}
func actionsRun(opts ActionsOptions) {
cs := opts.IO.ColorScheme()
fmt.Fprintln(opts.IO.Out, actionsExplainer(cs))
}

View file

@ -333,8 +333,10 @@ func Test_ioStreams_pager(t *testing.T) {
}
}
f := New("1")
if tt.config != nil {
f.Config = func() (config.Config, error) {
f.Config = func() (config.Config, error) {
if tt.config == nil {
return config.NewBlankConfig(), nil
} else {
return tt.config, nil
}
}
@ -363,8 +365,10 @@ func Test_ioStreams_prompt(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := New("1")
if tt.config != nil {
f.Config = func() (config.Config, error) {
f.Config = func() (config.Config, error) {
if tt.config == nil {
return config.NewBlankConfig(), nil
} else {
return tt.config, nil
}
}

View file

@ -58,7 +58,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
Gists can be created from one or multiple files. Alternatively, pass "-" as
file name to read from standard input.
By default, gists are private; use '--public' to make publicly listed ones.
By default, gists are secret; use '--public' to make publicly listed ones.
`),
Example: heredoc.Doc(`
# publish file 'hello.py' as a public gist
@ -97,7 +97,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co
cmd.Flags().StringVarP(&opts.Description, "desc", "d", "", "A description for this gist")
cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the web browser with created gist")
cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default: private)")
cmd.Flags().BoolVarP(&opts.Public, "public", "p", false, "List the gist publicly (default: secret)")
cmd.Flags().StringVarP(&opts.FilenameOverride, "filename", "f", "", "Provide a filename to be used when reading from STDIN")
return cmd
}

View file

@ -82,6 +82,9 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
cmd.Flags().StringVarP(&opts.Assignee, "assignee", "a", "", "Filter by assignee")
cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by labels")
cmd.Flags().StringVarP(&opts.State, "state", "s", "open", "Filter by state: {open|closed|all}")
_ = cmd.RegisterFlagCompletionFunc("state", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"open", "closed", "all"}, cobra.ShellCompDirectiveNoSpace
})
cmd.Flags().IntVarP(&opts.LimitResults, "limit", "L", 30, "Maximum number of issues to fetch")
cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author")
cmd.Flags().StringVar(&opts.Mention, "mention", "", "Filter by mention")

View file

@ -84,6 +84,9 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman
cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the browser to list the pull requests")
cmd.Flags().IntVarP(&opts.LimitResults, "limit", "L", 30, "Maximum number of items to fetch")
cmd.Flags().StringVarP(&opts.State, "state", "s", "open", "Filter by state: {open|closed|merged|all}")
_ = cmd.RegisterFlagCompletionFunc("state", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"open", "closed", "merged", "all"}, cobra.ShellCompDirectiveNoSpace
})
cmd.Flags().StringVarP(&opts.BaseBranch, "base", "B", "", "Filter by base branch")
cmd.Flags().StringSliceVarP(&opts.Labels, "label", "l", nil, "Filter by labels")
cmd.Flags().StringVarP(&opts.Author, "author", "A", "", "Filter by author")

View file

@ -5,9 +5,6 @@ import (
"github.com/spf13/cobra"
)
// TODO can have this set a PersistentPreRun so we don't have to set for all child commands of auth,
// config
func DisableAuthCheck(cmd *cobra.Command) {
if cmd.Annotations == nil {
cmd.Annotations = map[string]string{}
@ -37,7 +34,7 @@ func CheckAuth(cfg config.Config) bool {
}
func IsAuthCheckEnabled(cmd *cobra.Command) bool {
if !cmd.Runnable() {
if cmd.Name() == "help" {
return false
}
for c := cmd; c.Parent() != nil; c = c.Parent() {

View file

@ -7,12 +7,26 @@ import (
"github.com/spf13/cobra"
)
func executeParentHooks(cmd *cobra.Command, args []string) error {
for cmd.HasParent() {
cmd = cmd.Parent()
if cmd.PersistentPreRunE != nil {
return cmd.PersistentPreRunE(cmd, args)
}
}
return nil
}
func EnableRepoOverride(cmd *cobra.Command, f *Factory) {
cmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := executeParentHooks(cmd, args); err != nil {
return err
}
repoOverride, _ := cmd.Flags().GetString("repo")
f.BaseRepo = OverrideBaseRepoFunc(f, repoOverride)
return nil
}
}