Method: Launchr::Mixlib::CLI#filter_options_summary

Defined in:
lib/launchr/mixin/mixlib_cli.rb

#filter_options_summary(options_summary) ⇒ Object



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/launchr/mixin/mixlib_cli.rb', line 619

def filter_options_summary options_summary
  os = options_summary.split("\n")
  out = []

  short_args = @arguments.values.map do |args|
    args[:short] ? args[:short].sub(/([A-Z]|=|\s).*$/,"") : args[:short]
  end
  long_args = @arguments.values.map do |args|
    args[:long] ? args[:long].sub(/([A-Z]|=|\s).*$/,"") : args[:long]
  end

  os.each do |line|
    case line
    when banner
      out += [@header].flatten if @header
      unless line =~ /^\s*$/
        # line = " " + line if @spaced_summary
        out << line
      end
    else
      if @spaced_summary
        out << "" unless line =~ /^#{@opt_parser.summary_indent}\s{#{@opt_parser.summary_width},}/
      end

      line =~ /^\s+-((\[no-\])?\w+)\,?/
      short_opt = $1 || false
      line =~ /^\s+(-(\[no-\])?\w+\,?)?\s--((\[no-\])?\w+)/
      long_opt = $3 || false

      # line.sub!("-"+short_opt," "+short_opt)  if short_opt && short_args.include?("-#{short_opt}")
      # line.sub!("--"+long_opt,"  "+long_opt)  if long_opt && long_args.include?("--#{long_opt}")

      opt_value = {}
      @options_arguments.each do |key,value|
        if long_opt && value[:long_strip]
          if long_opt.sub(/^(-+)?\[no-\]/,"") == value[:long_strip].sub(/^-+/,"")
            # puts long_opt 
            opt_value = value
          end
        elsif short_opt && value[:short_strip]
          if short_opt.sub(/^(-+)?\[no-\]/,"") == value[:short_strip].sub(/^-+/,"")
            # puts short_opt 
            opt_value = value
          end
        end
      end
      line = "  " + line if opt_value[:indent]
      
      if short_opt && short_args.include?("-#{short_opt}")
        short_opt = @arguments.values[short_args.index("-#{short_opt}")][:short].sub(/^-+/,"")
        # short_opt = opt_value[:short].sub(/^-+/,"")
        line.sub!("-"+short_opt,short_opt+" ")
      end
      if long_opt && long_args.include?("--#{long_opt}")
        long_opt = @arguments.values[long_args.index("--#{long_opt}")][:long].sub(/^-+/,"")
        # long_opt = opt_value[:short].sub(/^-+/,"")
        line.sub!("--"+long_opt,long_opt+"  ")
      end

      out << line
    end
  end
  out << " " if @spaced_summary
  out += [@footer].flatten if @footer

  out
end