Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ All notable changes to `src-cli` are documented in this file.

### Changed

- For internal use only: `-text-only` now contains detailed information about task execution. [#571](https://github.com/sourcegraph/src-cli/pull/571)
- As part of the above: the TUI of `src batch [preview|apply]` has been reworked and should now feel snappier.

### Fixed

### Removed
Expand Down
9 changes: 5 additions & 4 deletions cmd/src/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package main
import (
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/mattn/go-isatty"
"github.com/sourcegraph/src-cli/internal/api"
"github.com/sourcegraph/src-cli/internal/cmderrors"

"github.com/mattn/go-isatty"
)

func init() {
Expand Down Expand Up @@ -65,7 +66,7 @@ Examples:
if query == "" {
// Read query from stdin instead.
if isatty.IsTerminal(os.Stdin.Fd()) {
return &usageError{errors.New("expected query to be piped into 'src api' or -query flag to be specified")}
return cmderrors.Usage("expected query to be piped into 'src api' or -query flag to be specified")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled these errors out into a separate package because one or two functions in the ui package that print them needed to check for their type.

}
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
Expand All @@ -84,7 +85,7 @@ Examples:
for _, arg := range flagSet.Args() {
idx := strings.Index(arg, "=")
if idx == -1 {
return &usageError{fmt.Errorf("parsing argument %q expected 'variable=value' syntax (missing equals)", arg)}
return cmderrors.Usagef("parsing argument %q expected 'variable=value' syntax (missing equals)", arg)
}
key := arg[:idx]
value := arg[idx+1:]
Expand Down
15 changes: 8 additions & 7 deletions cmd/src/batch_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"context"
"errors"
"flag"
"fmt"

"github.com/sourcegraph/sourcegraph/lib/output"
"github.com/sourcegraph/src-cli/internal/batches/ui"
"github.com/sourcegraph/src-cli/internal/cmderrors"
)

func init() {
Expand Down Expand Up @@ -35,18 +36,18 @@ Examples:
}

if len(flagSet.Args()) != 0 {
return &usageError{errors.New("additional arguments not allowed")}
return cmderrors.Usage("additional arguments not allowed")
}

ctx, cancel := contextCancelOnInterrupt(context.Background())
defer cancel()

var ui batchExecUI
var execUI ui.ExecUI
if flags.textOnly {
ui = &batchExecJSONLinesUI{}
execUI = &ui.JSONLines{}
} else {
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
ui = &batchExecTUI{out: out}
execUI = &ui.TUI{Out: out}
}

err := executeBatchSpec(ctx, executeBatchSpecOpts{
Expand All @@ -55,10 +56,10 @@ Examples:

applyBatchSpec: true,

ui: ui,
ui: execUI,
})
if err != nil {
return &exitCodeError{nil, 1}
return cmderrors.ExitCode(1, nil)
}

return nil
Expand Down
30 changes: 7 additions & 23 deletions cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ import (

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/sourcegraph/sourcegraph/lib/output"
"github.com/sourcegraph/src-cli/internal/api"
"github.com/sourcegraph/src-cli/internal/batches"
"github.com/sourcegraph/src-cli/internal/batches/executor"
"github.com/sourcegraph/src-cli/internal/batches/graphql"
"github.com/sourcegraph/src-cli/internal/batches/service"
"github.com/sourcegraph/src-cli/internal/batches/ui"
"github.com/sourcegraph/src-cli/internal/batches/workspace"
)

var (
batchPendingColor = output.StylePending
batchSuccessColor = output.StyleSuccess
batchSuccessEmoji = output.EmojiSuccess
"github.com/sourcegraph/src-cli/internal/cmderrors"
)

type batchExecuteFlags struct {
Expand Down Expand Up @@ -125,14 +120,6 @@ func newBatchExecuteFlags(flagSet *flag.FlagSet, cacheDir, tempDir string) *batc
return caf
}

func batchCreatePending(out *output.Output, message string) output.Pending {
return out.Pending(output.Line("", batchPendingColor, message))
}

func batchCompletePending(p output.Pending, message string) {
p.Complete(output.Line(batchSuccessEmoji, batchSuccessColor, message))
}

func batchDefaultCacheDir() string {
uc, err := os.UserCacheDir()
if err != nil {
Expand Down Expand Up @@ -199,7 +186,7 @@ type executeBatchSpecOpts struct {

applyBatchSpec bool

ui batchExecUI
ui ui.ExecUI

client api.Client
}
Expand Down Expand Up @@ -238,10 +225,7 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error
if err != nil {
if merr, ok := err.(*multierror.Error); ok {
opts.ui.ParsingBatchSpecFailure(merr)
return &exitCodeError{
error: nil,
exitCode: 2,
}
return cmderrors.ExitCode(2, nil)
} else {
// This shouldn't happen; let's just punt and let the normal
// rendering occur.
Expand Down Expand Up @@ -315,12 +299,12 @@ func executeBatchSpec(ctx context.Context, opts executeBatchSpecOpts) (err error
}
opts.ui.CheckingCacheSuccess(len(cachedSpecs), len(uncachedTasks))

printer := opts.ui.ExecutingTasks(*verbose, opts.flags.parallelism)
freshSpecs, logFiles, err := coord.Execute(ctx, uncachedTasks, batchSpec, printer)
taskExecUI := opts.ui.ExecutingTasks(*verbose, opts.flags.parallelism)
freshSpecs, logFiles, err := coord.Execute(ctx, uncachedTasks, batchSpec, taskExecUI)
if err != nil && !opts.flags.skipErrors {
return err
}
opts.ui.ExecutingTasksSuccess()
taskExecUI.Success()
if err != nil && opts.flags.skipErrors {
opts.ui.ExecutingTasksSkippingErrors(err)
}
Expand Down
Loading