diff --git a/README.md b/README.md index b4cde4f..6453364 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,42 @@ Up-to-date: /Users/suin/projects/myapp3 git-remind status-notification ``` +### Ad-hoc paths configuration + +The paths can be specified with `--path` option instead of git global configuration `remind.paths`. + +``` +$ git-remind --path '/path/to/dir/*' paths +/path/to/dir/* +``` + +The option accepts multiple paths giving two or more `--path` options. + +``` +$ git-remind --path '/path/to/dir1/*' --path '/path/to/dir2/*' paths +/path/to/dir1/* +/path/to/dir2/* +``` + +Also giving the environment variable `GIT_REMIND_PATHS`, it makes the same effect. + +``` +$ export GIT_REMIND_PATHS='/path/to/dir1/*,/path/to/dir2/*' +$ git-remind paths +/path/to/dir1/* +/path/to/dir2/* +``` + +When both of `--path` option and `GIT_REMIND_PATHS` are given, the paths become the combination of the both. + +``` +$ export GIT_REMIND_PATHS='/path/to/dir1/*,/path/to/dir2/*' +$ git-remind --path '/path/to/dir3/*' paths +/path/to/dir1/* +/path/to/dir2/* +/path/to/dir3/* +``` + ## Advanced usage ### Scheduled reminder (cron) diff --git a/app/appservice/service.go b/app/appservice/service.go index beb85b1..526ab72 100644 --- a/app/appservice/service.go +++ b/app/appservice/service.go @@ -1,11 +1,17 @@ package appservice import ( + "github.com/suin/git-remind/app/cli/cliglobalopts" "github.com/suin/git-remind/domain" "github.com/suin/git-remind/infra" ) -var GetPathPatterns = domain.NewGetPathPatterns(infra.GitGlobalConfigGetPathPatterns) +var GetPathPatterns = domain.NewGetPathPatterns( + domain.MultipleGetPathPatterns( + cliglobalopts.GetPathPatterns, + infra.GitGlobalConfigGetPathPatterns, + ), +) var GetRepos = domain.NewGetRepos(GetPathPatterns, infra.FilesystemRepos) var GetRepoStatuses = domain.NewGetRepoStatuses(GetRepos, infra.GetGitStatus) var NotifyRepoStatues = domain.NewNotifyRepoStatuses(GetRepoStatuses, infra.BeeepRepoStatusNotifier) diff --git a/app/cli/app.go b/app/cli/app.go index d80537b..e99b767 100644 --- a/app/cli/app.go +++ b/app/cli/app.go @@ -1,6 +1,7 @@ package cli import ( + "github.com/suin/git-remind/app/cli/cliglobalopts" "github.com/suin/git-remind/app/cli/commands" "github.com/urfave/cli" ) @@ -20,4 +21,15 @@ var App = &cli.App{ commands.StatusCommand, commands.StatusNotificationCommand, }, + Flags: []cli.Flag{ + cli.StringSliceFlag{ + Name: "path", + Usage: "Path patterns of git repositories. If this options is specified, The configuration of `remind.paths` in .gitconfig is ignored. You may specify multiple paths like --path=/path/to/a --path=/path/to/b", + EnvVar: "GIT_REMIND_PATHS", + }, + }, + Before: func(context *cli.Context) error { + cliglobalopts.SetPathPatterns(context.StringSlice("path")) + return nil + }, } diff --git a/app/cli/cliglobalopts/paths.go b/app/cli/cliglobalopts/paths.go new file mode 100644 index 0000000..da7d60b --- /dev/null +++ b/app/cli/cliglobalopts/paths.go @@ -0,0 +1,13 @@ +package cliglobalopts + +import "github.com/suin/git-remind/domain" + +var pathPatterns []string + +func SetPathPatterns(p []string) { + pathPatterns = p +} + +var GetPathPatterns domain.GetPathPatterns = func() ([]string, error) { + return pathPatterns, nil +} diff --git a/app/cli/commands/paths.go b/app/cli/commands/paths.go index c132f19..8e3e957 100644 --- a/app/cli/commands/paths.go +++ b/app/cli/commands/paths.go @@ -12,7 +12,7 @@ var PathsCommand = cli.Command{ Action: pathsAction, } -func pathsAction(*cli.Context) error { +func pathsAction(c *cli.Context) error { pathPatterns, err := appservice.GetPathPatterns() if err != nil { return err diff --git a/domain/get_path_patterns.go b/domain/get_path_patterns.go index 8dfe5c9..9fa8f07 100644 --- a/domain/get_path_patterns.go +++ b/domain/get_path_patterns.go @@ -7,3 +7,18 @@ func NewGetPathPatterns(pathPatterns GetPathPatterns) GetPathPatterns { return pathPatterns() } } + +func MultipleGetPathPatterns(multipleGetPathPatterns ...GetPathPatterns) GetPathPatterns { + return func() ([]string, error) { + for _, getPathPatterns := range multipleGetPathPatterns { + pathPatterns, err := getPathPatterns() + if err != nil { + return []string{}, err + } + if len(pathPatterns) > 0 { + return pathPatterns, nil + } + } + return []string{}, nil + } +}