Skip to content

Commit

Permalink
Add --cwd flag for status command
Browse files Browse the repository at this point in the history
  • Loading branch information
kilpkonn committed Sep 27, 2020
1 parent 7d7ddb2 commit da4b428
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ Options:
-tags="" Project tags to report status for, i.e --tags tag1,tag2
-all=false Show status for all projects
-cwd="" Set cwd (useful for plugins)
`
return strings.TrimSpace(helpText)
}

// Run executes status command with args
func (c StatusCmd) Run(args []string) int {
var color, terminalOff, appOff, totalOnly, all, profile, longDuration bool
var tags string
var tags, cwd string
cmdFlags := flag.NewFlagSet("status", flag.ContinueOnError)
cmdFlags.BoolVar(&color, "color", false, "Always output color even if no terminal is detected. Use this with pagers i.e 'less -R' or 'more -R'")
cmdFlags.BoolVar(&terminalOff, "terminal-off", false, "Exclude time spent in terminal (Terminal plugin is required)")
Expand All @@ -65,6 +67,7 @@ func (c StatusCmd) Run(args []string) int {
cmdFlags.BoolVar(&longDuration, "long-duration", false, "Display total time in long duration format")
cmdFlags.StringVar(&tags, "tags", "", "Project tags to show status on")
cmdFlags.BoolVar(&all, "all", false, "Show status for all projects")
cmdFlags.StringVar(&cwd, "cwd", "", "Set cwd")
cmdFlags.BoolVar(&profile, "profile", false, "Enable profiling")
cmdFlags.Usage = func() { c.UI.Output(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
Expand All @@ -77,6 +80,7 @@ func (c StatusCmd) Run(args []string) int {
}

var (
projects []string
err error
commitNote note.CommitNote
out string
Expand All @@ -93,7 +97,11 @@ func (c StatusCmd) Run(args []string) int {
tagList = util.Map(strings.Split(tags, ","), strings.TrimSpace)
}

projects, err := index.Get(tagList, all)
if cwd != "" {
projects, err = index.Get(tagList, all, cwd)
} else {
projects, err = index.Get(tagList, all)
}
if err != nil {
c.UI.Error(err.Error())
return 1
Expand Down
6 changes: 3 additions & 3 deletions project/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewIndex() (Index, error) {
}

// Get finds projects by tags or all projects or the project in the current directory
func (i *Index) Get(tags []string, all bool) ([]string, error) {
func (i *Index) Get(tags []string, all bool, cwd ...string) ([]string, error) {
switch {
case all:
err := i.clean()
Expand All @@ -45,7 +45,7 @@ func (i *Index) Get(tags []string, all bool) ([]string, error) {
if err := i.clean(); err != nil {
return []string{}, err
}
projectsWithTags := []string{}
var projectsWithTags []string
for _, p := range i.projects() {
found, err := i.hasTags(p, tags)
if err != nil {
Expand All @@ -58,7 +58,7 @@ func (i *Index) Get(tags []string, all bool) ([]string, error) {
sort.Strings(projectsWithTags)
return projectsWithTags, nil
default:
curProjPath, _, err := Paths()
curProjPath, _, err := Paths(cwd...)
if err != nil {
return []string{}, err
}
Expand Down

0 comments on commit da4b428

Please sign in to comment.