Skip to content

Commit

Permalink
allow status display output to be disabled
Browse files Browse the repository at this point in the history
really only helpful if someone JUST wants the machine parseable
version, but this could be useful and will also clean up our tests as
we think about z-mode.

As a side effect, cleaned up the opt parsing so there are no global
variables.
  • Loading branch information
mroth committed Mar 4, 2015
1 parent 7c0c059 commit 0204c4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
33 changes: 19 additions & 14 deletions commands/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/spf13/cobra"
)

var porcelainFiles bool

// CommandStatus processes 'git status --porcelain', and exports numbered
// env variables that contain the path of each affected file.
// Output is also more concise than standard 'git status'.
//
// TODO: Call with optional <group> parameter to filter by modification state:
// 1 || Staged, 2 || Unmerged, 3 || Unstaged, 4 || Untracked
func CommandStatus() *cobra.Command {
var optsFilelist bool
var optsDisplay bool

var statusCmd = &cobra.Command{
Use: "status",
Expand All @@ -35,15 +35,28 @@ sets the environment variables for your shell. (For more information on this,
see 'scmpuff init'.)
`,
Run: func(cmd *cobra.Command, args []string) {
runStatus()
root := gitProjectRoot()
status := gitStatusOutput()

results := Process(status, root)
results.printStatus(optsFilelist, optsDisplay)
},
}

// --aliases
// --filelist, -f
statusCmd.Flags().BoolVarP(
&porcelainFiles,
&optsFilelist,
"filelist", "f", false,
"include parseable filelist as first line of output",
"include machine-parseable filelist",
)

// --display
// allow normal display to be disabled, not really useful unless you know you
// JUST want the machine parseable file-list for some reason.
statusCmd.Flags().BoolVarP(
&optsDisplay,
"display", "", true,
"displays the formatted status output",
)

// --relative
Expand All @@ -58,14 +71,6 @@ see 'scmpuff init'.)
return statusCmd
}

func runStatus() {
root := gitProjectRoot()
status := gitStatusOutput()

results := Process(status, root)
results.printStatus(porcelainFiles)
}

// Runs `git status --porcelain` and returns the results.
//
// If an error is encountered, the process will die fatally.
Expand Down
22 changes: 12 additions & 10 deletions commands/status/statuslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,24 @@ func (sl StatusList) orderedItems() (items []*StatusItem) {
//
// if `includeParseData` is true, the first line will be a machine parseable
// list of files to be used for environment variable expansion.
func (sl StatusList) printStatus(includeParseData bool) {
func (sl StatusList) printStatus(includeParseData, includeStatusOutput bool) {
b := bufio.NewWriter(os.Stdout)

if includeParseData {
fmt.Fprintln(b, sl.dataForParsing())
}

fmt.Fprintln(b, sl.banner())

// keep track of number of items printed, and pass off information to each
// fileGroup, which knows how to print itself.
if sl.numItems() >= 1 {
startNum := 1
for _, fg := range sl.orderedGroups() {
fg.print(startNum, b)
startNum += len(fg.items)
if includeStatusOutput {
// print the banner
fmt.Fprintln(b, sl.banner())
// keep track of number of items printed, and pass off information to each
// fileGroup, which knows how to print itself.
if sl.numItems() >= 1 {
startNum := 1
for _, fg := range sl.orderedGroups() {
fg.print(startNum, b)
startNum += len(fg.items)
}
}
}

Expand Down

0 comments on commit 0204c4c

Please sign in to comment.