Skip to content

Commit

Permalink
Merge 724e462 into 0e80ee9
Browse files Browse the repository at this point in the history
  • Loading branch information
jawher committed Nov 9, 2017
2 parents 0e80ee9 + 724e462 commit 935a787
Show file tree
Hide file tree
Showing 59 changed files with 3,856 additions and 2,105 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
testdata/*.golden
coverage.out
*.coverprofile
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ go:
- tip
sudo: false

install: make setup
install:
- make setup
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls

script: make check test
script: make check test-cover

deploy:
provider: releases
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
test:
go test -v ./...

test-cover:
go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' ./... | xargs -L 1 sh -c
gover
goveralls -coverprofile=gover.coverprofile -service=travis-ci

check: lint vet fmtcheck ineffassign

lint:
Expand All @@ -20,6 +25,9 @@ ineffassign:
setup:
go get github.com/gordonklaus/ineffassign
go get github.com/golang/lint/golint
go get golang.org/x/tools/cmd/cover
go get github.com/mattn/goveralls
go get github.com/modocache/gover
go get -t -u ./...

.PHONY: test check lint vet fmtcheck ineffassign
26 changes: 7 additions & 19 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cli

import (
"flag"
"fmt"

"github.com/jawher/mow.cli/internal/container"
"github.com/jawher/mow.cli/internal/values"
)

// BoolArg describes a boolean argument
Expand Down Expand Up @@ -199,26 +201,12 @@ VarArg defines an argument where the type and format is controlled by the develo
The result will be stored in the value parameter (a value implementing the flag.Value interface) which will be populated when the app is run and the call arguments get parsed
*/
func (c *Cmd) VarArg(name string, value flag.Value, desc string) {
c.mkArg(arg{name: name, desc: desc, value: value})
}

type arg struct {
name string
desc string
envVar string
hideValue bool
valueSetFromEnv bool
valueSetByUser *bool
value flag.Value
}

func (a *arg) String() string {
return fmt.Sprintf("ARG(%s)", a.name)
c.mkArg(container.Container{Name: name, Desc: desc, Value: value})
}

func (c *Cmd) mkArg(arg arg) {
arg.valueSetFromEnv = setFromEnv(arg.value, arg.envVar)
func (c *Cmd) mkArg(arg container.Container) {
arg.ValueSetFromEnv = values.SetFromEnv(arg.Value, arg.EnvVar)

c.args = append(c.args, &arg)
c.argsIdx[arg.name] = &arg
c.argsIdx[arg.Name] = &arg
}
142 changes: 0 additions & 142 deletions args_test.go

This file was deleted.

23 changes: 12 additions & 11 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"io"
"os"

"github.com/jawher/mow.cli/internal/container"
"github.com/jawher/mow.cli/internal/flow"
)

/*
Expand All @@ -17,7 +20,7 @@ type Cli struct {

type cliVersion struct {
version string
option *opt
option *container.Container
}

/*
Expand All @@ -35,8 +38,8 @@ func App(name, desc string) *Cli {
Cmd: &Cmd{
name: name,
desc: desc,
optionsIdx: map[string]*opt{},
argsIdx: map[string]*arg{},
optionsIdx: map[string]*container.Container{},
argsIdx: map[string]*container.Container{},
ErrorHandling: flag.ExitOnError,
},
}
Expand All @@ -62,7 +65,7 @@ func (cli *Cli) Version(name, version string) {
cli.version = &cliVersion{version, option}
}

func (cli *Cli) parse(args []string, entry, inFlow, outFlow *step) error {
func (cli *Cli) parse(args []string, entry, inFlow, outFlow *flow.Step) error {
// We overload Cmd.parse() and handle cases that only apply to the CLI command, like versioning
// After that, we just call Cmd.parse() for the default behavior
if cli.versionSetAndRequested(args) {
Expand All @@ -74,7 +77,7 @@ func (cli *Cli) parse(args []string, entry, inFlow, outFlow *step) error {
}

func (cli *Cli) versionSetAndRequested(args []string) bool {
return cli.version != nil && cli.isFlagSet(args, cli.version.option.names)
return cli.version != nil && cli.isFlagSet(args, cli.version.option.Names)
}

/*
Expand All @@ -97,15 +100,15 @@ func (cli *Cli) Run(args []string) error {
if err := cli.doInit(); err != nil {
panic(err)
}
inFlow := &step{desc: "RootIn"}
outFlow := &step{desc: "RootOut"}
inFlow := &flow.Step{Desc: "RootIn", Exiter: exiter}
outFlow := &flow.Step{Desc: "RootOut", Exiter: exiter}
return cli.parse(args[1:], inFlow, inFlow, outFlow)
}

/*
ActionCommand is a convenience function to configure a command with an action.
cmd.ActionCommand(_, _, myFun } is equivalent to cmd.Command(_, _, func(cmd *cli.Cmd) { cmd.Action = myFun })
cmd.ActionCommand(_, _, myFunc) is equivalent to cmd.Command(_, _, func(cmd *cli.Cmd) { cmd.Action = myFunc })
*/
func ActionCommand(action func()) CmdInitializer {
return func(cmd *Cmd) {
Expand All @@ -118,11 +121,9 @@ Exit causes the app the exit with the specified exit code while giving the After
This should be used instead of os.Exit.
*/
func Exit(code int) {
panic(exit(code))
panic(flow.ExitCode(code))
}

type exit int

var exiter = func(code int) {
os.Exit(code)
}
Expand Down
Loading

0 comments on commit 935a787

Please sign in to comment.