Skip to content

Commit 6a8d2cb

Browse files
pierrelalanneagateau-gg
authored andcommitted
feat(cli): improve CLI options naming to make them consistent
1 parent c94234a commit 6a8d2cb

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,20 @@ repositories. You can override this limit with the option `--limit`, a limit of
7777

7878
### Default behavior
7979

80-
Note that by default **for github provider**, `src-fingerprint` will exclude private repositories, forks and archived repositories from the fingerprints computation. Use options `-e` or `--all` to change this behavior.
80+
Note that by default, `src-fingerprint` will exclude forked repositories from the fingerprints computation. **For GitHub provider** archived repositories and public repositories will also be excluded by default. Use flags `--include-forked-repos`, `--include-archived-repos` or `include-public-repos` to change this behavior.
8181

8282
### GitHub
8383

8484
1. Export all fingerprints from private repositories from a GitHub Org to the default path `./fingerprints.jsonl.gz` with logs:
8585

8686
```sh
87-
env VCS_TOKEN="<token>" src-fingerprint -v --provider github --object ORG_NAME --all
87+
env VCS_TOKEN="<token>" src-fingerprint -v --provider github --object ORG_NAME
8888
```
8989

9090
2. Export all fingerprints of every repository the user can access to the default path `./fingerprints.jsonl.gz`:
9191

9292
```sh
93-
env VCS_TOKEN="<token>" src-fingerprint -v --provider github --all
93+
env VCS_TOKEN="<token>" src-fingerprint -v --provider github --include-public-repos --include-forked-repos --include-archived-repos
9494
```
9595

9696
### GitLab
@@ -103,10 +103,8 @@ env VCS_TOKEN="<token>" src-fingerprint -v --provider gitlab --object "GitGuardi
103103

104104
2. Export all fingerprints of every project the user can access to the default path `./fingerprints.jsonl.gz` with logs:
105105

106-
> :warning: On `gitlab.com` this will attempt to retrieve all repositories on `gitlab.com`
107-
108106
```sh
109-
env VCS_TOKEN="<token>" src-fingerprint -v --provider gitlab
107+
env VCS_TOKEN="<token>" src-fingerprint -v --provider gitlab --include-forked-repos
110108
```
111109

112110
### Bitbucket server (formely Atlassian Stash)

cmd/src-fingerprint/main.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,17 @@ func main() {
9999
Usage: "verbose logging",
100100
},
101101
&cli.BoolFlag{
102-
Name: "extract-forks",
103-
Aliases: []string{"e"},
104-
Value: false,
105-
Usage: "extract fork repositories when possible",
102+
Name: "include-forked-repos",
103+
Value: false,
104+
Usage: "include forked repositories when possible",
105+
},
106+
&cli.BoolFlag{
107+
Name: "include-public-repos",
108+
Value: false,
109+
Usage: "Include fileshas from both public and private repositories if the provider is 'github'",
106110
},
107111
&cli.BoolFlag{
108-
Name: "skip-archived",
112+
Name: "include-archived-repos",
109113
Value: false,
110114
Usage: "skip archived repositories",
111115
},
@@ -137,11 +141,6 @@ func main() {
137141
Required: true,
138142
Usage: "vcs provider. options: 'gitlab'/'github'/'bitbucket'/'repository'",
139143
},
140-
&cli.BoolFlag{
141-
Name: "all",
142-
Value: false,
143-
Usage: "Collect fileshas from every accessible repository including public ones if the provider is 'github'",
144-
},
145144
&cli.StringFlag{
146145
Name: "repo-name",
147146
Usage: "Name of the repository to display in outputs if the provider is 'repository'",
@@ -218,10 +217,10 @@ func mainAction(c *cli.Context) error {
218217
var srcCloner cloner.Cloner = cloner.NewDiskCloner(c.String("clone-dir"))
219218

220219
providerOptions := provider.Options{
221-
OmitForks: !c.Bool("extract-forks"),
222-
SkipArchived: c.Bool("skip-archived"),
220+
IncludeForkedRepos: c.Bool("include-forked-repos"),
221+
IncludeArchivedRepos: c.Bool("include-archived-repos"),
222+
IncludePublicRepos: c.Bool("include-public-repos"),
223223
BaseURL: c.String("provider-url"),
224-
AllRepositories: c.Bool("all"),
225224
RepositoryName: c.String("repo-name"),
226225
RespositoryIsPrivate: c.Bool("repo-is-private"),
227226
}

provider/github.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (p *GitHubProvider) gatherPage(user string, page int) ([]GitRepository, err
8181
visibility string
8282
)
8383

84-
if p.options.AllRepositories {
84+
if p.options.IncludePublicRepos {
8585
visibility = "all"
8686
} else {
8787
visibility = "private"
@@ -123,11 +123,11 @@ func (p *GitHubProvider) gatherPage(user string, page int) ([]GitRepository, err
123123
repositories := make([]GitRepository, 0, len(repos))
124124

125125
for _, repo := range repos {
126-
if p.options.OmitForks && repo.GetFork() {
126+
if !p.options.IncludeForkedRepos && repo.GetFork() {
127127
continue
128128
}
129129

130-
if p.options.SkipArchived && repo.Archived != nil && *repo.Archived {
130+
if !p.options.IncludeArchivedRepos && repo.Archived != nil && *repo.Archived {
131131
continue
132132
}
133133

provider/gitlab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (p *GitLabProvider) gatherAccessiblePage(page int, verbose bool) ([]GitRepo
8282
repositories := make([]GitRepository, 0, len(repos))
8383

8484
for _, repo := range repos {
85-
if p.options.OmitForks && repo.ForkedFromProject != nil {
85+
if !p.options.IncludeForkedRepos && repo.ForkedFromProject != nil {
8686
continue
8787
}
8888

@@ -112,7 +112,7 @@ func (p *GitLabProvider) gatherGroupProjectPage(groupID, page int, verbose bool)
112112
repositories := make([]GitRepository, 0, len(repos))
113113

114114
for _, repo := range repos {
115-
if p.options.OmitForks && repo.ForkedFromProject != nil {
115+
if !p.options.IncludeForkedRepos && repo.ForkedFromProject != nil {
116116
continue
117117
}
118118

provider/provider.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ type Provider interface {
3838

3939
// Options represents options for the Provider.
4040
type Options struct {
41-
// OmitForks will tell the Provider to omit fork repositories
42-
OmitForks bool
43-
// SkipArchived will skip archived repositories
44-
SkipArchived bool
41+
// IncludeForkedRepos will include fork repositories in fingerprints computation
42+
// This is available for GitLab and GitHub providers only.
43+
IncludeForkedRepos bool
44+
// IncludeArchivedRepos will include archived repositories in fingerprints computation
45+
// This is only available for GitHub provider only.
46+
IncludeArchivedRepos bool
47+
// IncludePublicRepos will include public repositories in fingerprints computation
48+
// This is only available for GitHub provider only.
49+
IncludePublicRepos bool
4550
// Repository private status to display in the output if the provider is 'repository'
4651
RespositoryIsPrivate bool
47-
// AllRepositories collects fileshas from every accessible repository
48-
// including public ones. This is only used by "github" provider
49-
AllRepositories bool
5052
// BaseURL is the base URL of the API
5153
BaseURL string
5254
// Repository name to display in the output if the provider is 'repository'

0 commit comments

Comments
 (0)