diff options
Diffstat (limited to 'lib/sisu/v3/options.rb')
| -rw-r--r-- | lib/sisu/v3/options.rb | 334 | 
1 files changed, 240 insertions, 94 deletions
| diff --git a/lib/sisu/v3/options.rb b/lib/sisu/v3/options.rb index c594aac4..11d03e1d 100644 --- a/lib/sisu/v3/options.rb +++ b/lib/sisu/v3/options.rb @@ -57,7 +57,7 @@      parsing  =end -module SiSU_commandline +module SiSU_Commandline    require "pathname"    require_relative 'sysenv'                             # sysenv.rb    @@base_path=nil @@ -66,9 +66,9 @@ module SiSU_commandline      def initialize(a)        @cmd,@f_pth,@pth,@fns,@fnb,@fnc,@fncb,@what,@lng,@lng_base,@base_path,@base_stub,@sub_location='','','','','','','','','','','','',''        @f_pths,@files,@paths,@mod,@act=Array.new(5){[]} -      @env=SiSU_Env::Info_env.new +      @env=SiSU_Env::InfoEnv.new        @lng_base=@env.language_default_set -      @dir_structure_by=SiSU_Env::Env_call.new.output_dir_structure.by? +      @dir_structure_by=SiSU_Env::EnvCall.new.output_dir_structure.by?        @@base_path ||=Dir.pwd        @base_path=@@base_path        r=Px[:lng_lst].join('|') @@ -87,7 +87,8 @@ module SiSU_commandline              x << Dir.glob("#{d}/*.ss[tm]")            end          end -        opt + x.flatten! +        x=x.flatten +        opt + x        end      end      def find_select(find_flag,opt) @@ -112,8 +113,8 @@ module SiSU_commandline              end            end          end -        x.flatten! -     end +        x.flatten +      end      end      def sisu_glob_rules(a)        a=if a.inspect =~/"-[A-Za-z0-9]*[fG]/ \ @@ -140,7 +141,7 @@ module SiSU_commandline            end          end          r=Px[:lng_lst].join('|') -        r.gsub!(/\|#{@lng_base}\|/,'|') +        r=r.gsub(/\|#{@lng_base}\|/,'|')          @lang_regx=%r{(?:#{r})}          z=if find_flag            (f.length > 0) \ @@ -182,13 +183,13 @@ module SiSU_commandline          if @files.length > 0 \          and @cmd.empty? \          and @mod.length==0 #% if no other action called on filename given, default is sisu --v3 -0 [filename(s)] configured as flag default -          shortcut=SiSU_Env::Info_processing_flag.new +          shortcut=SiSU_Env::InfoProcessingFlag.new            @mod=['--v3']            @cmd=shortcut.cf_0 + 'm'          end          SiSU_Screen::Ansi.new(@cmd,"\tsisu " + @cmd +  ' ' + @mod.join(' ') + ' ' + @files.join(' ') + "\n").print_brown if @cmd =~/[vVM]/        end -#     @files.uniq! +#     @files=@files.uniq        @act=opt_act        @files        self @@ -229,7 +230,7 @@ module SiSU_commandline              fn = (y[r_f,1]) \                ? y[r_f,1]                : y -            fn.gsub!(/\.((?:ssm\.)?sst)/,'.-\1') +            fn=fn.gsub(/\.((?:ssm\.)?sst)/,'.-\1')              fullname=Dir.pwd + '/' + fn              pt=Pathname.new(fullname)              pth << Dir.pwd @@ -304,7 +305,7 @@ module SiSU_commandline        { cmd: c, mod: m, what: w, paths: pth, files: f, f_pths: f_pths, lng: lng, lngs: lngs }      end      def expand_numeric_shortcuts(a) -      shortcut=SiSU_Env::Info_processing_flag.new +      shortcut=SiSU_Env::InfoProcessingFlag.new        s=''        a.each do |x|          y=case x @@ -361,6 +362,7 @@ module SiSU_commandline            when /^--(?:xhtml)$/;                              c=c+'b'            when /^--(?:xml-sax)$/;                            c=c+'x'            when /^--(?:xml-dom)$/;                            c=c+'X' +          when /^--(?:images)$/;                             c=c+'j'            when /^--(?:hash-digests)$/;                       c=c+'N'            when /^--(?:po4a|pot?)$/;                          c=c+'P'            when /^--(?:termsheet)$/;                          c=c+'T' @@ -388,7 +390,7 @@ module SiSU_commandline        end        ca=[]        unless c.empty? -        c.gsub!(/-/,'') +        c=c.gsub(/-/,'')          c.scan(/CC|\S/) {|x| ca << x}          cmd= '-' + ca.uniq.join        end @@ -405,6 +407,13 @@ module SiSU_commandline          else ''          end        end +      if cmd !~/j/ +        extra+=if cmd =~/[bHhwXxyz]/ \ +        and cmd !~/[j]/ +          'j'                        #% copy images +        else '' +        end +      end        if cmd !~/y/          extra+=if cmd =~/[abeHhIiNopsSstwXxz]/ \          and cmd !~/y/ @@ -426,31 +435,47 @@ module SiSU_commandline        act={}        act[:license]=(cmd =~/L/ \        || mod.inspect =~/"--license/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:site_init]=(cmd =~/C/ \        || mod.inspect =~/"--init-site/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on  } +      : { bool: false, set: :na }        act[:rc]=if mod.inspect =~/"--rc=/          x=Dir.pwd + '/' + mod.join.gsub(/--rc=/,'') -        { bool: true, inst: x  } +        { bool: true, set: :on, inst: x } +      else +        { bool: false, set: :na, inst: '' } +      end +      act[:dump]=if mod.inspect =~/"--dump=/ +        base_pth=mod.join(';').gsub(/^.*--dump=['"]?(.+?)(?:['"]?;.+)?$/,'\1') +        { bool: true, set: :on, inst: base_pth } +      elsif mod.inspect =~/"--dump/ +        { bool: true, set: :on, inst: @base_path }        else -        { bool: false, inst: '' } +        { bool: false, set: :na, inst: nil } +      end +      act[:redirect]=if mod.inspect =~/"--redirect=/ +        base_pth=mod.join(';').gsub(/^.*--redirect=['"]?(.+?)(?:['"]?;.+)?$/,'\1') +        { bool: true, set: :on, inst: base_pth } +      elsif mod.inspect =~/"--redirect/ +        { bool: true, set: :on, inst: @base_path } +      else +        { bool: false, set: :na, inst: nil }        end        act[:verbose]=(cmd =~/v/ \        || mod.inspect =~/"--verbose"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:quiet]=(cmd =~/q/ \        || mod.inspect =~/"--quiet"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:color_state]=if mod.inspect =~/"--color-on"|"--color"/ -        { bool: true } +        { bool: true, set: :on }        elsif mod.inspect =~/"--color-off"/ -        { bool: false } -      else { bool: true } #fix default color +        { bool: false, set: :off } +      else { bool: true, set: :na } #fix default color        end  #     act[:color_toggle]=if cmd =~/c/ \  #     or mod.inspect =~/"--color-toggle"/ @@ -459,138 +484,259 @@ module SiSU_commandline  #     end        act[:maintenance]=(cmd =~/M/ \        || mod.inspect =~/"--maintenance|--keep-processing-files"/) \ -      ? { bool: true } -      : { bool: false } -      act[:ocn]=if mod.inspect =~/"--no-ocn"/ -         { bool: false } -      else { bool: true } +      ? { bool: true, set: :on } +      : { bool: false, set: :na } +      act[:switch]=if mod.inspect =~/"--switch-off=/ +        off_list=mod.join(';').gsub(/^.*--switch-off=['"]?(.+?)(?:['"];.+)?$/,'\1') +        off_list=off_list.scan(/[^,;\s]+/) +        { bool: false, set: :off, off: off_list} +      else { bool: true, set: :na, off: [] } +      end +      act[:ocn]= +      if mod.inspect =~/"--inc-ocn"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-ocn"/ \ +      || act[:switch][:off].inspect =~/"ocn"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:toc]=if mod.inspect =~/"--inc-toc"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-toc"/ \ +      || act[:switch][:off].inspect =~/"toc"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:minitoc]=if mod.inspect =~/"--inc-minitoc"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-minitoc"/ \ +      || act[:switch][:off].inspect =~/"minitoc"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:manifest]=if mod.inspect =~/"--inc-manifest"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-manifest"/ \ +      || act[:switch][:off].inspect =~/"manifest"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:links_to_manifest]=if mod.inspect =~/"--inc-links-to-manifest"|"--inc-manifest-links"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-links-to-manifest"|"--(?:exc|no)-manifest-links"/ \ +      || act[:switch][:off].inspect =~/"links_to_manifest"|"manifest_links"/ \ +      || mod.inspect =~/"--(?:redirect|dump)/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:manifest_minitoc]=if mod.inspect =~/"--inc-manifest-minitoc"|"--inc-minitoc"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-manifest-minitoc"|"--(?:exc|no)-minitoc"/ \ +      || act[:switch][:off].inspect =~/"manifest_minitoc"|"minitoc"/ +      #|| mod.inspect =~/"--(?:redirect|dump)/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:metadata]=if mod.inspect =~/"--inc-metadata"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-metadata"/ \ +      || act[:switch][:off].inspect =~/"metadata"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:html_minitoc]=if mod.inspect =~/"--inc-html-minitoc"|"--inc-minitoc"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-html-minitoc"|"--(?:exc|no)-minitoc"/ \ +      || act[:switch][:off].inspect =~/"html_minitoc"|"minitoc"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:html_navigation]=if mod.inspect =~/"--inc-html-navigation"|"--inc-navigation"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-html-navigation"|"--(?:exc|no)-navigation"/ \ +      || act[:switch][:off].inspect =~/"html_navigation"|"nav"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:html_navigation_bar]=if mod.inspect =~/"--inc-html-navigation-bar"|"--inc-navigation-bar"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-html-navigation-bar"|"--(?:exc|no)-navigation-bar"/ \ +      || act[:switch][:off].inspect =~/"html_navigation_bar"|"navbar"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:segsubtoc]=if mod.inspect =~/"--inc-segsubtoc"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-segsubtoc"/ \ +      || act[:switch][:off].inspect =~/"segsubtoc"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:search_form]=if mod.inspect =~/"--inc-search-form"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-search-form"/ \ +      || act[:switch][:off].inspect =~/"search_form"|"search"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:html_search_form]=if mod.inspect =~/"--inc-html-search-form"|"--inc-search-form"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-html-search-form"|"--(?:exc|no)-search-form"/ \ +      || act[:switch][:off].inspect =~/"html_search_form"|"search_form"|"search"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:html_right_pane]=if mod.inspect =~/"--inc-html-right-pane"|"--inc-right-pane"|"--inc-html-right-column"|"--inc-right-column"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-html-right-pane"|"--(?:exc|no)-right-pane"|"--(?:exc|no)-html-right-column"|"--(?:exc|no)-right-column"/ \ +      || act[:switch][:off].inspect =~/"html_right_pane"|"html_right_column"|"promo"/ +        { bool: false, set: :off } +      else { bool: true, set: :na } +      end +      act[:html_top_band]=if mod.inspect =~/"--inc-html-top-band"|"--inc-top-band"/ +        { bool: true, set: :on } +      elsif mod.inspect =~/"--(?:exc|no)-html-top-band"|"--(?:exc|no)-top-band"/ \ +      || act[:switch][:off].inspect =~/"html-top-band"|"top-band"/ +        { bool: false, set: :off } +      else { bool: true, set: :na }        end        act[:dal]=(cmd =~/m/ \        || mod.inspect =~/"--dal"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:html]=(cmd =~/h/ \        || mod.inspect =~/"--html"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:concordance]=(cmd =~/w/ \        || mod.inspect =~/"--concordance"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na } +      act[:images]=(cmd =~/j/ \ +      || mod.inspect =~/"--images"/) \ +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:pdf]=(cmd =~/p/ \        || mod.inspect =~/"--pdf"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:epub]=(cmd =~/e/ \        || mod.inspect =~/"--epub"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:odt]=(cmd =~/o/ \        || mod.inspect =~/"--odf"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:xml_sax]=(cmd =~/x/ \        || mod.inspect =~/"--xml-sax"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:xml_dom]=(cmd =~/X/ \        || mod.inspect =~/"--xml-dom"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:xhtml]=(cmd =~/b/ \        || mod.inspect =~/"--xhtml"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:txt]=(cmd =~/[at]/ \        || mod.inspect =~/"--txt"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:manpage]=(cmd =~/i/ \        || mod.inspect =~/"--manpage"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:texinfo]=(cmd =~/I/ \        || mod.inspect =~/"--texinfo"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:fictionbook]=(cmd =~/f/ \        || mod.inspect =~/"--fictionbook"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:psql]=(cmd =~/D/ \        || mod.inspect =~/"--pg"|"--pgsql"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:sqlite]=(cmd =~/d/ \        || mod.inspect =~/"--sqlite"/) \ -      ? { bool: true } -      : { bool: false } +      && (mod.inspect =~/"--createdb"|"--create"|"--recreate"|"--dropall"|"--recreate"|"--import"|"--update"|"--remove"/) \ +      ? { bool: true, set: :on } +      : { bool: false, set: :na } +      act[:sqlite_discreet]=(cmd =~/d/ \ +      || mod.inspect =~/"--sql"|"--sqlite"/) \ +      && (mod.inspect =~/"--both"/ \ +      || mod.inspect !~/"--createdb"|"--create"|"--recreate"|"--dropall"|"--recreate"|"--import"|"--update"|"--remove"/) \ +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:harvest]=(mod.inspect =~/"--harvest"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:po4a]=(cmd =~/P/ \        || mod.inspect =~/"--po4a"|"--pot?"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:git]=(cmd =~/g/ \        || mod.inspect =~/"--git"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:hash_digests]=(cmd =~/N/ \        || mod.inspect =~/"--hash-digests"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:sample_search_form]=(cmd =~/F/ \        || mod.inspect =~/"--sample-search-form"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:webrick]=(cmd =~/W/ \        || mod.inspect =~/"--webrick"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:share_source]=(cmd =~/s/ \        || mod.inspect =~/"--source"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:sisupod]=(cmd =~/S/ \        || mod.inspect =~/"--sisupod"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:scp]=(cmd =~/r/ \        || mod.inspect =~/"--scp"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:rsync]=(cmd =~/R/ \        || mod.inspect =~/"--rsync"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:delete_output]=(cmd =~/z/ \        || mod.inspect =~/"--delete"|"--zap"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:urls_all]=(cmd =~/U/ \        || mod.inspect =~/"--urls-all"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:urls_seleted]=(cmd =~/u/ \        || mod.inspect =~/"--urls"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:sitemap]=(cmd =~/Y/ \        || mod.inspect =~/"--sitemap"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:qrcode]=(cmd =~/Q/ \        || mod.inspect =~/"--qrcode"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:manifest]=(cmd =~/y/ \        || mod.inspect =~/"--manifest"/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        act[:help]=(mod.inspect =~/"--help/) \ -      ? { bool: true } -      : { bool: false } +      ? { bool: true, set: :on } +      : { bool: false, set: :na }        @act=act      end      def cmd | 
