Skip to content

Commit

Permalink
new: support --archived and --no-archived options for "repos" subcomm…
Browse files Browse the repository at this point in the history
…and (fix: #155)
  • Loading branch information
kyoh86 committed Jul 28, 2024
1 parent 74dffb7 commit 784dc95
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
37 changes: 27 additions & 10 deletions cmd/gogh/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ import (
)

type reposFlagsStruct struct {
Format string `yaml:"format,omitempty"`
Color string `yaml:"color,omitempty"`
Sort string `yaml:"sort,omitempty"`
Order string `yaml:"order,omitempty"`
Relation []string `yaml:"relation,omitempty"`
Limit int `yaml:"limit,omitempty"`
Private bool `yaml:"private,omitempty"`
Public bool `yaml:"public,omitempty"`
Fork bool `yaml:"fork,omitempty"`
NotFork bool `yaml:"notFork,omitempty"`
Format string `yaml:"format,omitempty"`
Color string `yaml:"color,omitempty"`
Sort string `yaml:"sort,omitempty"`
Order string `yaml:"order,omitempty"`
Relation []string `yaml:"relation,omitempty"`
Limit int `yaml:"limit,omitempty"`
Private bool `yaml:"private,omitempty"`
Public bool `yaml:"public,omitempty"`
Fork bool `yaml:"fork,omitempty"`
NotFork bool `yaml:"notFork,omitempty"`
Archived bool `yaml:"archived,omitempty"`
NotArchived bool `yaml:"notArchived,omitempty"`
}

var (
Expand Down Expand Up @@ -66,6 +68,16 @@ var (
if reposFlags.NotFork {
listOption.IsFork = &reposFlags.Fork // &false
}

if reposFlags.Archived && reposFlags.NotArchived {
return errors.New("specify only one of `--archived` or `--no-archived`")
}
if reposFlags.Archived {
listOption.IsArchived = &reposFlags.Archived // &true
}
if reposFlags.NotArchived {
listOption.IsArchived = &reposFlags.Archived // &false
}
LOOP_CONVERT_RELATION:
for _, r := range reposFlags.Relation {
rdef := gogh.RepositoryRelation(r)
Expand Down Expand Up @@ -185,6 +197,11 @@ func init() {
reposCommand.Flags().
BoolVarP(&reposFlags.NotFork, "no-fork", "", defaultFlag.Repos.NotFork, "Omit forks")

reposCommand.Flags().
BoolVarP(&reposFlags.Archived, "archived", "", defaultFlag.Repos.Archived, "Show only archived repositories")
reposCommand.Flags().
BoolVarP(&reposFlags.NotArchived, "no-archived", "", defaultFlag.Repos.NotArchived, "Omit archived repositories")

reposCommand.Flags().
StringVarP(&reposFlags.Format, "format", "", defaultString(defaultFlag.Repos.Format, "table"), fmt.Sprintf("The formatting style for each repository; it can accept %s", quoteEnums(repoFormatAccept)))
if err := reposCommand.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
16 changes: 9 additions & 7 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ var AllOrderDirection = []githubv4.OrderDirection{
}

type RemoteListOption struct {
Private *bool
IsFork *bool
Order OrderDirection
Sort RepositoryOrderField
Relation []RepositoryRelation
Limit int
Private *bool
IsFork *bool
IsArchived *bool
Order OrderDirection
Sort RepositoryOrderField
Relation []RepositoryRelation
Limit int
}

func (o *RemoteListOption) GetOptions() *github.RepositoryListOptions {
Expand All @@ -124,7 +125,8 @@ func (o *RemoteListOption) GetOptions() *github.RepositoryListOptions {
}
}
opt := &github.RepositoryListOptions{
IsFork: o.IsFork,
IsFork: o.IsFork,
IsArchived: o.IsArchived,
}

if o.Sort == "" {
Expand Down

0 comments on commit 784dc95

Please sign in to comment.