...

Source file src/github.com/urfave/cli/v2/args.go

Documentation: github.com/urfave/cli/v2

     1  package cli
     2  
     3  type Args interface {
     4  	// Get returns the nth argument, or else a blank string
     5  	Get(n int) string
     6  	// First returns the first argument, or else a blank string
     7  	First() string
     8  	// Tail returns the rest of the arguments (not the first one)
     9  	// or else an empty string slice
    10  	Tail() []string
    11  	// Len returns the length of the wrapped slice
    12  	Len() int
    13  	// Present checks if there are any arguments present
    14  	Present() bool
    15  	// Slice returns a copy of the internal slice
    16  	Slice() []string
    17  }
    18  
    19  type args []string
    20  
    21  func (a *args) Get(n int) string {
    22  	if len(*a) > n {
    23  		return (*a)[n]
    24  	}
    25  	return ""
    26  }
    27  
    28  func (a *args) First() string {
    29  	return a.Get(0)
    30  }
    31  
    32  func (a *args) Tail() []string {
    33  	if a.Len() >= 2 {
    34  		tail := []string((*a)[1:])
    35  		ret := make([]string, len(tail))
    36  		copy(ret, tail)
    37  		return ret
    38  	}
    39  	return []string{}
    40  }
    41  
    42  func (a *args) Len() int {
    43  	return len(*a)
    44  }
    45  
    46  func (a *args) Present() bool {
    47  	return a.Len() != 0
    48  }
    49  
    50  func (a *args) Slice() []string {
    51  	ret := make([]string, len(*a))
    52  	copy(ret, *a)
    53  	return ret
    54  }
    55  

View as plain text