Skip to content

Commit

Permalink
Merge pull request #1784 from urfave/collapse-context-command
Browse files Browse the repository at this point in the history
Collapse `Context` into `Command`
  • Loading branch information
meatballhat authored Jun 29, 2023
2 parents fc3b515 + ef500f2 commit fbb9421
Show file tree
Hide file tree
Showing 32 changed files with 2,217 additions and 2,225 deletions.
29 changes: 16 additions & 13 deletions args.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,42 @@ type Args interface {
Slice() []string
}

type args []string
type stringSliceArgs struct {
v []string
}

func (a *args) Get(n int) string {
if len(*a) > n {
return (*a)[n]
func (a *stringSliceArgs) Get(n int) string {
if len(a.v) > n {
return a.v[n]
}
return ""
}

func (a *args) First() string {
func (a *stringSliceArgs) First() string {
return a.Get(0)
}

func (a *args) Tail() []string {
func (a *stringSliceArgs) Tail() []string {
if a.Len() >= 2 {
tail := []string((*a)[1:])
tail := a.v[1:]
ret := make([]string, len(tail))
copy(ret, tail)
return ret
}

return []string{}
}

func (a *args) Len() int {
return len(*a)
func (a *stringSliceArgs) Len() int {
return len(a.v)
}

func (a *args) Present() bool {
func (a *stringSliceArgs) Present() bool {
return a.Len() != 0
}

func (a *args) Slice() []string {
ret := make([]string, len(*a))
copy(ret, *a)
func (a *stringSliceArgs) Slice() []string {
ret := make([]string, len(a.v))
copy(ret, a.v)
return ret
}
Loading

0 comments on commit fbb9421

Please sign in to comment.