diff --git a/pkg/cmd/secret/list/list.go b/pkg/cmd/secret/list/list.go index b5eb85dc5..e1c8e32f1 100644 --- a/pkg/cmd/secret/list/list.go +++ b/pkg/cmd/secret/list/list.go @@ -47,8 +47,7 @@ func NewCmdList(f *cmdutil.Factory, runF func(*ListOptions) error) *cobra.Comman }, } - cmd.Flags().StringVar(&opts.OrgName, "org", "", "List secrets for an organization") - cmd.Flags().Lookup("org").NoOptDefVal = "@owner" + cmd.Flags().StringVarP(&opts.OrgName, "org", "o", "", "List secrets for an organization") return cmd } @@ -60,26 +59,21 @@ func listRun(opts *ListOptions) error { } client := api.NewClientFromHTTP(c) + orgName := opts.OrgName + var baseRepo ghrepo.Interface - if opts.OrgName == "" || opts.OrgName == "@owner" { + if orgName == "" { baseRepo, err = opts.BaseRepo() if err != nil { return fmt.Errorf("could not determine base repo: %w", err) } } - orgName := opts.OrgName - host := ghinstance.OverridableDefault() - if orgName == "@owner" { - orgName = baseRepo.RepoOwner() - host = baseRepo.RepoHost() - } - var secrets []Secret - if orgName != "" { - secrets, err = getOrgSecrets(client, host, orgName) - } else { + if orgName == "" { secrets, err = getRepoSecrets(client, baseRepo) + } else { + secrets, err = getOrgSecrets(client, orgName) } if err != nil { @@ -131,7 +125,8 @@ func fmtVisibility(s Secret) string { return "" } -func getOrgSecrets(client *api.Client, host, orgName string) ([]Secret, error) { +func getOrgSecrets(client *api.Client, orgName string) ([]Secret, error) { + host := ghinstance.OverridableDefault() return getSecrets(client, host, fmt.Sprintf("orgs/%s/actions/secrets", orgName)) } diff --git a/pkg/cmd/secret/list/list_test.go b/pkg/cmd/secret/list/list_test.go index 8a7077de1..960680455 100644 --- a/pkg/cmd/secret/list/list_test.go +++ b/pkg/cmd/secret/list/list_test.go @@ -31,15 +31,8 @@ func Test_NewCmdList(t *testing.T) { }, }, { - name: "implicit org", - cli: "--org", - wants: ListOptions{ - OrgName: "@owner", - }, - }, - { - name: "explicit org", - cli: "--org=UmbrellaCorporation", + name: "org", + cli: "-oUmbrellaCorporation", wants: ListOptions{ OrgName: "UmbrellaCorporation", }, @@ -105,7 +98,7 @@ func Test_listRun(t *testing.T) { }, }, { - name: "explicit org tty", + name: "org tty", tty: true, opts: &ListOptions{ OrgName: "UmbrellaCorporation", @@ -117,7 +110,7 @@ func Test_listRun(t *testing.T) { }, }, { - name: "explicit org not tty", + name: "org not tty", tty: false, opts: &ListOptions{ OrgName: "UmbrellaCorporation", @@ -128,30 +121,6 @@ func Test_listRun(t *testing.T) { "SECRET_THREE\t1975-11-30\tSELECTED", }, }, - { - name: "implicit org not tty", - tty: false, - opts: &ListOptions{ - OrgName: "@owner", - }, - wantOut: []string{ - "SECRET_ONE\t1988-10-11\tALL", - "SECRET_TWO\t2020-12-04\tPRIVATE", - "SECRET_THREE\t1975-11-30\tSELECTED", - }, - }, - { - name: "implicit org not tty", - tty: true, - opts: &ListOptions{ - OrgName: "@owner", - }, - wantOut: []string{ - "SECRET_ONE.*Updated 1988-10-11.*Visible to all repositories", - "SECRET_TWO.*Updated 2020-12-04.*Visible to private repositories", - "SECRET_THREE.*Updated 1975-11-30.*Visible to selected repositories", - }, - }, } for _, tt := range tests { @@ -195,11 +164,7 @@ func Test_listRun(t *testing.T) { Visibility: shared.VisSelected, }, } - if tt.opts.OrgName == "@owner" { - path = "orgs/owner/actions/secrets" - } else { - path = fmt.Sprintf("orgs/%s/actions/secrets", tt.opts.OrgName) - } + path = fmt.Sprintf("orgs/%s/actions/secrets", tt.opts.OrgName) } reg.Register(httpmock.REST("GET", path), httpmock.JSONResponse(payload))