From 0204c4c396e601674e2de86e655a69af41bb1696 Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Wed, 4 Mar 2015 16:10:57 -0500 Subject: [PATCH] allow status display output to be disabled 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. --- commands/status/status.go | 33 +++++++++++++++++++-------------- commands/status/statuslist.go | 22 ++++++++++++---------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/commands/status/status.go b/commands/status/status.go index d70046b..7ef26f6 100644 --- a/commands/status/status.go +++ b/commands/status/status.go @@ -10,8 +10,6 @@ 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'. @@ -19,6 +17,8 @@ var porcelainFiles bool // TODO: Call with optional 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", @@ -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 @@ -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. diff --git a/commands/status/statuslist.go b/commands/status/statuslist.go index 7646d41..574af78 100644 --- a/commands/status/statuslist.go +++ b/commands/status/statuslist.go @@ -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) + } } }