arg-parse-gen.rb
##
# Generate the state machine for this argument as a sequence of bash if statements.
Generate the state machine for this argument as a sequence of bash if statements.
Generate the state machine for this argument as a sequence of bash if statements .
def generate_bash_sequence
      accumulator = [
         "    if [[ \"$arg\" = \"--#{@argument_name}\" ]]; then",
         '      if [[ "$current_argument" ]]; then',
         '        echo We were already parsing an argument: $current_argument.',
         '        echo We were looking for a value but saw another argument: $arg.',
         '        exit 1',
         '      fi']
      if @opts[:boolean]
        addendum = [
         "      arguments[\"#{@argument_name}\"]=true",
         '      multi_arg=false',
         ]
      elsif @opts[:multi]
        addendum = [
         '      multi_arg=true',
         "      current_argument=\"#{@argument_name}\"",
        ]
      else
        addendum = [
         "      current_argument=\"#{@argument_name}\"",
         '      multi_arg=false',
         ]
      end
      addendum.reduce(accumulator) {|m, line| m << line; m}
      accumulator << '      continue'
      accumulator << '    fi'
      accumulator
    end
def generate_bash_sequence accumulator = [ "    if [[ \"$arg\" = \"--#{@argument_name}\" ]]; then" , '      if [[ "$current_argument" ]]; then' , '        echo We were already parsing an argument: $current_argument.' , '        echo We were looking for a value but saw another argument: $arg.' , '        exit 1' , '      fi' ] if @opts [ :boolean ] addendum = [ "      arguments[\"#{@argument_name}\"]=true" , '      multi_arg=false' , ] elsif @opts [ :multi ] addendum = [ '      multi_arg=true' , "      current_argument=\"#{@argument_name}\"" , ] else addendum = [ "      current_argument=\"#{@argument_name}\"" , '      multi_arg=false' , ] end addendum . reduce ( accumulator ) { | m , line | m << line ; m } accumulator << '      continue' accumulator << '    fi' accumulator end
Generate the state machine for this argument as a sequence of bash if statements.
Generate the state machine for this argument as a sequence of bash if statements .