Skip to content

Commit

Permalink
feat: Add --path option and GIT_REMIND_PATHS environment
Browse files Browse the repository at this point in the history
  • Loading branch information
suin committed Nov 2, 2018
1 parent b7aad62 commit 29d159a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion app/appservice/service.go
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions app/cli/app.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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
},
}
13 changes: 13 additions & 0 deletions app/cli/cliglobalopts/paths.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion app/cli/commands/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions domain/get_path_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 29d159a

Please sign in to comment.