~shabbyrobe/cmdy

0c71cd457136d4b8015d2337231ed3b1781e7c8c — Blake Williams 1 year, 6 months ago bfe5b67 v0.9.0
Vanity
M README.md => README.md +5 -5
@@ 1,8 1,8 @@
cmdy: Go library for implementing CLI programs
==============================================

[![GoDoc](https://godoc.org/github.com/shabbyrobe/cmdy?status.svg)](https://godoc.org/github.com/shabbyrobe/cmdy)
![Go](https://github.com/shabbyrobe/cmdy/workflows/Go/badge.svg)
[![GoDoc](https://godoc.org/go.shabbyrobe.org/cmdy?status.svg)](https://godoc.org/go.shabbyrobe.org/cmdy)
![Go](https://go.shabbyrobe.org/cmdy/workflows/Go/badge.svg)

`cmdy` combines the features I like from the `flag` stdlib package with the
features I like from https://github.com/google/subcommands.


@@ 14,7 14,7 @@ my own projects. There are a lot of CLI libraries for Go but this one is mine.
much as possible. It does not attempt to replace `flag.Flag`, though it does
extend it slightly.

`cmdy` is liberally documented in [GoDoc](https://godoc.org/github.com/shabbyrobe/cmdy),
`cmdy` is liberally documented in [GoDoc](https://godoc.org/go.shabbyrobe.org/cmdy),
though a brief overview is provided in this README. If anything is unclear, please
submit a GitHub issue.



@@ 25,7 25,7 @@ Features
--------

- `ArgSet`, similar to `flag.FlagSet` but for positional arguments. The
  `github.com/shabbyrobe/cmdy/arg` package can be used independently.
  `go.shabbyrobe.org/cmdy/arg` package can be used independently.
- Simple subcommand (and sub-sub command (and sub-sub-sub command)) support.
- `context.Context` support (via `cmdy.Context`, which is also a
  `context.Context`).


@@ 112,7 112,7 @@ func (cmd *demoCommand) Help() cmdy.Help {
```

You can also add examples (which can be run using 
`github.com/shabbyrobe/cmdy/cmdytest.ExampleTester` to the `cmdy.Help` structure.
`go.shabbyrobe.org/cmdy/cmdytest.ExampleTester` to the `cmdy.Help` structure.
Individual fields are explained in more detail in godoc:

```go

M arg/argset.go => arg/argset.go +1 -1
@@ 4,7 4,7 @@ import (
	"fmt"
	"time"

	"github.com/shabbyrobe/cmdy/usage"
	"go.shabbyrobe.org/cmdy/usage"
)

// An ArgSet represents a set of defined command-line arguments. It is intended

M arg/argset_test.go => arg/argset_test.go +1 -1
@@ 4,7 4,7 @@ import (
	"strings"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestArgSetOneString(t *testing.T) {

M arg/var_test.go => arg/var_test.go +1 -1
@@ 5,7 5,7 @@ import (
	"log"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func ExampleArgSet_RemainingInts() {

M cmdytest/exampletester.go => cmdytest/exampletester.go +2 -2
@@ 7,8 7,8 @@ import (
	"strings"
	"testing"

	"github.com/shabbyrobe/cmdy"
	"github.com/shabbyrobe/cmdy/internal/cmdstr"
	"go.shabbyrobe.org/cmdy"
	"go.shabbyrobe.org/cmdy/internal/cmdstr"
)

// ExampleTester tests a set of examples from a cmdy.Help.

M cmdytest/exampletester_test.go => cmdytest/exampletester_test.go +2 -2
@@ 4,8 4,8 @@ import (
	"fmt"
	"testing"

	"github.com/shabbyrobe/cmdy"
	"github.com/shabbyrobe/cmdy/arg"
	"go.shabbyrobe.org/cmdy"
	"go.shabbyrobe.org/cmdy/arg"
)

type testCommand struct {

M cmdyutil/signal.go => cmdyutil/signal.go +1 -1
@@ 7,7 7,7 @@ import (
	"os/signal"
	"time"

	"github.com/shabbyrobe/cmdy"
	"go.shabbyrobe.org/cmdy"
)

const DefaultInterruptTimeout = 2 * time.Second

M cmdyutil/stdinorfile.go => cmdyutil/stdinorfile.go +1 -1
@@ 8,7 8,7 @@ import (
	"io/ioutil"
	"os"

	"github.com/shabbyrobe/cmdy"
	"go.shabbyrobe.org/cmdy"
)

type StdinFlag int

M cmdyutil/stdinorfile_test.go => cmdyutil/stdinorfile_test.go +1 -1
@@ 8,7 8,7 @@ import (
	"reflect"
	"testing"

	"github.com/shabbyrobe/cmdy"
	"go.shabbyrobe.org/cmdy"
)

type testContext struct {

M command.go => command.go +1 -1
@@ 1,7 1,7 @@
package cmdy

import (
	"github.com/shabbyrobe/cmdy/arg"
	"go.shabbyrobe.org/cmdy/arg"
)

/*

M command_test.go => command_test.go +2 -2
@@ 4,8 4,8 @@ import (
	"context"
	"testing"

	"github.com/shabbyrobe/cmdy/arg"
	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/arg"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestCommand_FlagsArgs(t *testing.T) {

M error_test.go => error_test.go +1 -1
@@ 5,7 5,7 @@ import (
	"fmt"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestFormatErrorQuiet(t *testing.T) {

M example_command_test.go => example_command_test.go +2 -2
@@ 4,8 4,8 @@ import (
	"context"
	"fmt"

	"github.com/shabbyrobe/cmdy"
	"github.com/shabbyrobe/cmdy/arg"
	"go.shabbyrobe.org/cmdy"
	"go.shabbyrobe.org/cmdy/arg"
)

type myCommand struct {

M example_maingroup_test.go => example_maingroup_test.go +2 -2
@@ 4,8 4,8 @@ import (
	"context"
	"fmt"

	"github.com/shabbyrobe/cmdy"
	"github.com/shabbyrobe/cmdy/arg"
	"go.shabbyrobe.org/cmdy"
	"go.shabbyrobe.org/cmdy/arg"
)

type mainGroupCommand struct{}

M flag.go => flag.go +1 -1
@@ 4,7 4,7 @@ import (
	"flag"
	"fmt"

	"github.com/shabbyrobe/cmdy/usage"
	"go.shabbyrobe.org/cmdy/usage"
)

// FlagDoubleDash allows you to globally configure whether long flag names will

M flag_test.go => flag_test.go +1 -1
@@ 5,7 5,7 @@ import (
	"testing"
	"time"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

const expectedUsage = `

M flags/optional_test.go => flags/optional_test.go +1 -1
@@ 5,7 5,7 @@ import (
	"flag"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestOptionalString(t *testing.T) {

M flags/val_test.go => flags/val_test.go +2 -2
@@ 7,8 7,8 @@ import (
	"strconv"
	"testing"

	"github.com/shabbyrobe/cmdy"
	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestStringList(t *testing.T) {

M go.mod => go.mod +2 -2
@@ 1,3 1,3 @@
module github.com/shabbyrobe/cmdy
module go.shabbyrobe.org/cmdy

go 1.13
go 1.19

M go.mod.fix => go.mod.fix +2 -2
@@ 1,3 1,3 @@
module github.com/shabbyrobe/cmdy
module go.shabbyrobe.org/cmdy

go 1.13
go 1.19

M group.go => group.go +2 -2
@@ 5,8 5,8 @@ import (
	"sort"
	"strings"

	"github.com/shabbyrobe/cmdy/arg"
	"github.com/shabbyrobe/cmdy/internal/wrap"
	"go.shabbyrobe.org/cmdy/arg"
	"go.shabbyrobe.org/cmdy/internal/wrap"
)

// Matcher is a function for choosing a command builder from a list of command builders

M group_test.go => group_test.go +2 -2
@@ 7,8 7,8 @@ import (
	"strings"
	"testing"

	"github.com/shabbyrobe/cmdy/arg"
	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/arg"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func strOutputBuilder(out string) func() Command {

M help.go => help.go +2 -2
@@ 4,8 4,8 @@ import (
	"fmt"
	"strings"

	"github.com/shabbyrobe/cmdy/arg"
	"github.com/shabbyrobe/cmdy/internal/wrap"
	"go.shabbyrobe.org/cmdy/arg"
	"go.shabbyrobe.org/cmdy/internal/wrap"
)

// DefaultUsage exists for compatibility with earlier versions.

M help_test.go => help_test.go +1 -1
@@ 4,7 4,7 @@ import (
	"strings"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

const exampleRenderResult = `

M init_test.go => init_test.go +1 -1
@@ 1,7 1,7 @@
package cmdy

import (
	"github.com/shabbyrobe/cmdy/arg"
	"go.shabbyrobe.org/cmdy/arg"
)

type testCmd struct {

M internal/cmdstr/cmdstr_test.go => internal/cmdstr/cmdstr_test.go +1 -1
@@ 6,7 6,7 @@ import (
	"strings"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func yep(t *testing.T, in string, out ...string) {

M matcher_test.go => matcher_test.go +1 -1
@@ 3,7 3,7 @@ package cmdy
import (
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestMatcher(t *testing.T) {

M misc.go => misc.go +1 -1
@@ 4,7 4,7 @@ import (
	"io"
	"os"

	"github.com/shabbyrobe/cmdy/internal/istty"
	"go.shabbyrobe.org/cmdy/internal/istty"
)

// ReaderIsPipe probably returns true if the input is receiving piped data

M misc_test.go => misc_test.go +1 -1
@@ 11,7 11,7 @@ import (
	"strings"
	"testing"

	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

var pipeSource = `

M run.go => run.go +1 -1
@@ 7,7 7,7 @@ import (
	"io"
	"os"

	"github.com/shabbyrobe/cmdy/arg"
	"go.shabbyrobe.org/cmdy/arg"
)

var (

M run_test.go => run_test.go +2 -2
@@ 5,8 5,8 @@ import (
	"fmt"
	"testing"

	"github.com/shabbyrobe/cmdy/arg"
	"github.com/shabbyrobe/cmdy/internal/assert"
	"go.shabbyrobe.org/cmdy/arg"
	"go.shabbyrobe.org/cmdy/internal/assert"
)

func TestRun(t *testing.T) {

M tools.sh => tools.sh +2 -2
@@ 3,11 3,11 @@ set -o errexit -o nounset -o pipefail

cmd-test() {
    go vet ./...
    go test -count=1 github.com/shabbyrobe/cmdy/...
    go test -count=1 go.shabbyrobe.org/cmdy/...
}

cmd-testcvg() {
    go test -coverprofile=cover.out github.com/shabbyrobe/cmdy/...
    go test -coverprofile=cover.out go.shabbyrobe.org/cmdy/...
    go tool cover -html=cover.out
}


M usage/usage.go => usage/usage.go +1 -1
@@ 5,7 5,7 @@ import (
	"reflect"
	"strings"

	"github.com/shabbyrobe/cmdy/internal/wrap"
	"go.shabbyrobe.org/cmdy/internal/wrap"
)

const indent = "        "