"Fossies" - the Fresh Open Source Software Archive

Member "gdrive-2.1.1/cli/flags.go" (28 May 2021, 2963 Bytes) of package /linux/misc/old/gdrive-2.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package cli
    2 
    3 type Flag interface {
    4     GetPatterns() []string
    5     GetName() string
    6     GetDescription() string
    7     GetParser() Parser
    8 }
    9 
   10 func getFlagParser(flags []Flag) Parser {
   11     var parsers []Parser
   12 
   13     for _, flag := range flags {
   14         parsers = append(parsers, flag.GetParser())
   15     }
   16 
   17     return FlagParser{parsers}
   18 }
   19 
   20 type BoolFlag struct {
   21     Patterns     []string
   22     Name         string
   23     Description  string
   24     DefaultValue bool
   25     OmitValue    bool
   26 }
   27 
   28 func (self BoolFlag) GetName() string {
   29     return self.Name
   30 }
   31 
   32 func (self BoolFlag) GetPatterns() []string {
   33     return self.Patterns
   34 }
   35 
   36 func (self BoolFlag) GetDescription() string {
   37     return self.Description
   38 }
   39 
   40 func (self BoolFlag) GetParser() Parser {
   41     var parsers []Parser
   42     for _, p := range self.Patterns {
   43         parsers = append(parsers, BoolFlagParser{
   44             pattern:      p,
   45             key:          self.Name,
   46             omitValue:    self.OmitValue,
   47             defaultValue: self.DefaultValue,
   48         })
   49     }
   50 
   51     if len(parsers) == 1 {
   52         return parsers[0]
   53     }
   54     return ShortCircuitParser{parsers}
   55 }
   56 
   57 type StringFlag struct {
   58     Patterns     []string
   59     Name         string
   60     Description  string
   61     DefaultValue string
   62 }
   63 
   64 func (self StringFlag) GetName() string {
   65     return self.Name
   66 }
   67 
   68 func (self StringFlag) GetPatterns() []string {
   69     return self.Patterns
   70 }
   71 
   72 func (self StringFlag) GetDescription() string {
   73     return self.Description
   74 }
   75 
   76 func (self StringFlag) GetParser() Parser {
   77     var parsers []Parser
   78     for _, p := range self.Patterns {
   79         parsers = append(parsers, StringFlagParser{
   80             pattern:      p,
   81             key:          self.Name,
   82             defaultValue: self.DefaultValue,
   83         })
   84     }
   85 
   86     if len(parsers) == 1 {
   87         return parsers[0]
   88     }
   89     return ShortCircuitParser{parsers}
   90 }
   91 
   92 type IntFlag struct {
   93     Patterns     []string
   94     Name         string
   95     Description  string
   96     DefaultValue int64
   97 }
   98 
   99 func (self IntFlag) GetName() string {
  100     return self.Name
  101 }
  102 
  103 func (self IntFlag) GetPatterns() []string {
  104     return self.Patterns
  105 }
  106 
  107 func (self IntFlag) GetDescription() string {
  108     return self.Description
  109 }
  110 
  111 func (self IntFlag) GetParser() Parser {
  112     var parsers []Parser
  113     for _, p := range self.Patterns {
  114         parsers = append(parsers, IntFlagParser{
  115             pattern:      p,
  116             key:          self.Name,
  117             defaultValue: self.DefaultValue,
  118         })
  119     }
  120 
  121     if len(parsers) == 1 {
  122         return parsers[0]
  123     }
  124     return ShortCircuitParser{parsers}
  125 }
  126 
  127 type StringSliceFlag struct {
  128     Patterns     []string
  129     Name         string
  130     Description  string
  131     DefaultValue []string
  132 }
  133 
  134 func (self StringSliceFlag) GetName() string {
  135     return self.Name
  136 }
  137 
  138 func (self StringSliceFlag) GetPatterns() []string {
  139     return self.Patterns
  140 }
  141 
  142 func (self StringSliceFlag) GetDescription() string {
  143     return self.Description
  144 }
  145 
  146 func (self StringSliceFlag) GetParser() Parser {
  147     var parsers []Parser
  148     for _, p := range self.Patterns {
  149         parsers = append(parsers, StringSliceFlagParser{
  150             pattern:      p,
  151             key:          self.Name,
  152             defaultValue: self.DefaultValue,
  153         })
  154     }
  155 
  156     if len(parsers) == 1 {
  157         return parsers[0]
  158     }
  159     return ShortCircuitParser{parsers}
  160 }