From 3b69ea6fbc603f631711c31a443e43744eaeb08c Mon Sep 17 00:00:00 2001 From: nobe4 Date: Tue, 7 Jan 2025 12:01:02 +0100 Subject: [PATCH 1/6] feat: make the extension upgrade fancier This left-pad the extension names during upgrade so they all align nicely. It makes easier to see what is happening. --- pkg/cmd/extension/manager.go | 11 ++++++++++- pkg/cmd/extension/manager_test.go | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 269d58ae0..49c448b7e 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -469,9 +469,18 @@ func (m *Manager) Upgrade(name string, force bool) error { } func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error { + var longestExtName = 0 + for _, ext := range exts { + l := len(ext.Name()) + if len(ext.Name()) > longestExtName { + longestExtName = l + } + } + format := fmt.Sprintf("[%%%ds]: ", longestExtName) + var failed bool for _, f := range exts { - fmt.Fprintf(m.io.Out, "[%s]: ", f.Name()) + fmt.Fprintf(m.io.Out, format, f.Name()) currentVersion := displayExtensionVersion(f, f.CurrentVersion()) err := m.upgradeExtension(f, force) if err != nil { diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go index 025d6e125..b83f17185 100644 --- a/pkg/cmd/extension/manager_test.go +++ b/pkg/cmd/extension/manager_test.go @@ -256,7 +256,7 @@ func TestManager_UpgradeExtensions(t *testing.T) { ` [hello]: upgraded from old vers to new vers [local]: local extensions can not be upgraded - [two]: upgraded from old vers to new vers + [ two]: upgraded from old vers to new vers `, ), stdout.String()) assert.Equal(t, "", stderr.String()) @@ -293,7 +293,7 @@ func TestManager_UpgradeExtensions_DryRun(t *testing.T) { ` [hello]: would have upgraded from 0 to 1 [local]: local extensions can not be upgraded - [two]: would have upgraded from 2 to 3 + [ two]: would have upgraded from 2 to 3 `, ), stdout.String()) assert.Equal(t, "", stderr.String()) From 954d4d5dbc6254f2e868ccf97fa5c6aae1cda275 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Thu, 9 Jan 2025 11:08:18 -0500 Subject: [PATCH 2/6] Correct help documentation around template use in `gh issue create` Relates #10202 While we figure out how to handle consistent experience using templates for creating issues and PRs, let's correct the help usage for issue template flag use as this is the issue template name, not filename. --- pkg/cmd/issue/create/create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/issue/create/create.go b/pkg/cmd/issue/create/create.go index f51cde4c9..2e3e0de51 100644 --- a/pkg/cmd/issue/create/create.go +++ b/pkg/cmd/issue/create/create.go @@ -72,7 +72,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co $ gh issue create --assignee monalisa,hubot $ gh issue create --assignee "@me" $ gh issue create --project "Roadmap" - $ gh issue create --template "bug_report.md" + $ gh issue create --template "Bug Report" `), Args: cmdutil.NoArgsQuoteReminder, Aliases: []string{"new"}, @@ -129,7 +129,7 @@ func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Co cmd.Flags().StringSliceVarP(&opts.Projects, "project", "p", nil, "Add the issue to projects by `title`") cmd.Flags().StringVarP(&opts.Milestone, "milestone", "m", "", "Add the issue to a milestone by `name`") cmd.Flags().StringVar(&opts.RecoverFile, "recover", "", "Recover input from a failed run of create") - cmd.Flags().StringVarP(&opts.Template, "template", "T", "", "Template `file` to use as starting body text") + cmd.Flags().StringVarP(&opts.Template, "template", "T", "", "Template `name` to use as starting body text") return cmd } From 567624b5506355e466ac4ff4a7d094f62f48e2fd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:39:26 +0000 Subject: [PATCH 3/6] Bump github.com/mattn/go-colorable from 0.1.13 to 0.1.14 Bumps [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable) from 0.1.13 to 0.1.14. - [Commits](https://github.com/mattn/go-colorable/compare/v0.1.13...v0.1.14) --- updated-dependencies: - dependency-name: github.com/mattn/go-colorable dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index f2f1ce812..cd7a82036 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/in-toto/attestation v1.1.0 github.com/joho/godotenv v1.5.1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 - github.com/mattn/go-colorable v0.1.13 + github.com/mattn/go-colorable v0.1.14 github.com/mattn/go-isatty v0.0.20 github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d github.com/microsoft/dev-tunnels v0.0.25 @@ -160,7 +160,7 @@ require ( golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect golang.org/x/mod v0.21.0 // indirect golang.org/x/net v0.33.0 // indirect - golang.org/x/sys v0.28.0 // indirect + golang.org/x/sys v0.29.0 // indirect golang.org/x/tools v0.26.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect diff --git a/go.sum b/go.sum index 1b48f0c27..0ec9bcd6a 100644 --- a/go.sum +++ b/go.sum @@ -303,10 +303,9 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= @@ -514,11 +513,10 @@ golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= From 1899b835092f6467426734ea72469038f1f3e7db Mon Sep 17 00:00:00 2001 From: nobe4 Date: Fri, 10 Jan 2025 16:28:50 +0100 Subject: [PATCH 4/6] fix: padded display Apply code suggestion from @andyfeller from: - https://github.com/cli/cli/pull/10194#discussion_r1909761552 - https://github.com/cli/cli/pull/10194#discussion_r1909764278 --- pkg/cmd/extension/manager.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 49c448b7e..32f0be26c 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -11,6 +11,7 @@ import ( "path" "path/filepath" "runtime" + "slices" "strings" "sync" @@ -469,18 +470,23 @@ func (m *Manager) Upgrade(name string, force bool) error { } func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error { - var longestExtName = 0 - for _, ext := range exts { - l := len(ext.Name()) - if len(ext.Name()) > longestExtName { - longestExtName = l + var longestExt = slices.MaxFunc(exts, func(a, b *Extension) int { + la, lb := len(a.Name()), len(b.Name()) + if la == lb { + return 0 } - } - format := fmt.Sprintf("[%%%ds]: ", longestExtName) + + if la < lb { + return -1 + } + + return 1 + }) + var longestExtName = len(longestExt.Name()) var failed bool for _, f := range exts { - fmt.Fprintf(m.io.Out, format, f.Name()) + fmt.Fprintf(m.io.Out, "[%*s] ", longestExtName, f.Name()) currentVersion := displayExtensionVersion(f, f.CurrentVersion()) err := m.upgradeExtension(f, force) if err != nil { From 69ab0c9c85c42f95900ec64951ef8351c6c45fdf Mon Sep 17 00:00:00 2001 From: nobe4 Date: Fri, 10 Jan 2025 16:31:13 +0100 Subject: [PATCH 5/6] fix: actually read how MaxFunc work and simplify the code --- pkg/cmd/extension/manager.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 32f0be26c..c82d6e856 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -471,16 +471,7 @@ func (m *Manager) Upgrade(name string, force bool) error { func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error { var longestExt = slices.MaxFunc(exts, func(a, b *Extension) int { - la, lb := len(a.Name()), len(b.Name()) - if la == lb { - return 0 - } - - if la < lb { - return -1 - } - - return 1 + return len(a.Name()) - len(b.Name()) }) var longestExtName = len(longestExt.Name()) From 69b17272d60ce36d785e416f40bace47b8fe8b05 Mon Sep 17 00:00:00 2001 From: nobe4 Date: Fri, 10 Jan 2025 17:17:14 +0100 Subject: [PATCH 6/6] fix: add back colon that I removed --- pkg/cmd/extension/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index c82d6e856..7f4bcfd70 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -477,7 +477,7 @@ func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error { var failed bool for _, f := range exts { - fmt.Fprintf(m.io.Out, "[%*s] ", longestExtName, f.Name()) + fmt.Fprintf(m.io.Out, "[%*s]: ", longestExtName, f.Name()) currentVersion := displayExtensionVersion(f, f.CurrentVersion()) err := m.upgradeExtension(f, force) if err != nil {