diff options
Diffstat (limited to 'lib/sisu/v3/options.rb')
-rw-r--r-- | lib/sisu/v3/options.rb | 426 |
1 files changed, 334 insertions, 92 deletions
diff --git a/lib/sisu/v3/options.rb b/lib/sisu/v3/options.rb index a79b08f3..a1a448e6 100644 --- a/lib/sisu/v3/options.rb +++ b/lib/sisu/v3/options.rb @@ -61,11 +61,11 @@ module SiSU_commandline require "pathname" require_relative 'sysenv' # sysenv.rb class Options - attr_accessor :cmd,:mod,:f_pths,:files,:paths,:f_pth,:pth,:fns,:fnb,:fnc,:fncb,:what + attr_accessor :cmd,:mod,:act,:f_pths,:files,:paths,:f_pth,:pth,:fns,:fnb,:fnc,:fncb,:lng,:what def initialize(a) @a=a @cmd,@f_pth,@pth,@fns,@fnb,@fnc,@fncb,@what='','','','','','','','','' - @f_pths,@files,@paths,@mod=[],[],[],[] + @f_pths,@files,@paths,@mod,@act=Array.new(5){[]} @env=SiSU_Env::Info_env.new r=Px[:lng_lst].join('|') #r.gsub!(/\|en\|/,'|') @@ -102,44 +102,27 @@ module SiSU_commandline end def init a=@a - c,w,s='','','' - m,f,pth,z,ca=[],[],[],[],[] - shortcut=SiSU_Env::Info_processing_flag.new - a.each do |x| - y=case x - when /0/ - (x=~/^-1\S+/) \ - ? x.gsub(/^-0(\S+)/,shortcut.cf_0 + ' -\1') \ - : x.gsub(/^-0/,shortcut.cf_0 + ' ') - when /1/ - (x=~/^-1\S+/) \ - ? x.gsub(/^-1(\S+)/,shortcut.cf_1 + ' -\1') \ - : x.gsub(/^-1/,shortcut.cf_1 + ' ') - when /2/ - (x=~/^-2\S+/) \ - ? x.gsub(/^-2(\S+)/,shortcut.cf_2 + ' -\1') \ - : x.gsub(/^-2/,shortcut.cf_2 + ' ') - when /3/ - (x=~/^-3\S+/) \ - ? x.gsub(/^-3(\S+)/,shortcut.cf_3 + ' -\1') \ - : x.gsub(/^-3/,shortcut.cf_3 + ' ') - when /4/ - (x=~/^-4\S+/) \ - ? x.gsub(/^-4(\S+)/,shortcut.cf_4 + ' -\1') \ - : x.gsub(/^-4/,shortcut.cf_4 + ' ') - when /5/ - (x=~/^-5\S+/) \ - ? x.gsub(/^-5(\S+)/,shortcut.cf_5 + ' -\1') \ - : x.gsub(/^-5/,shortcut.cf_5 + ' ') - when /6/ - (x=~/^-6\S+/) \ - ? x.gsub(/^-6(\S+)/,shortcut.cf_5 + ' -\1') \ - : x.gsub(/^-6/,shortcut.cf_5 + ' ') - else x - end - s << " #{y}" unless y.empty? + s=expand_numeric_shortcuts(a) + q=set_files_and_paths_and_general_extract(s) + @cmd,@mod=opt_cmd_and_mod_adjust(q[:cmd],q[:mod]) + @what=q[:what] unless q[:what].empty? + @paths = q[:paths] + @files = q[:files] + @f_pths = q[:f_pths] + if @files.length > 0 \ + and @cmd.empty? \ + and @mod.length==0 #% if no other action called on filename given, default is sisu -0 [filename(s)] configured as flag default + @cmd=shortcut.cf_0 end - s.strip! + SiSU_Screen::Ansi.new(@cmd,"\tsisu " + @cmd + ' ' + @mod.join(' ') + ' ' + @files.join(' ') + "\n").print_brown if @cmd =~/[vVM]/ +# @files.uniq! + @act=opt_act + @files + self + end + def set_files_and_paths_and_general_extract(s) + c,w='','' + m,f,pth,z,lng=[],[],[],[],[] a=s.split(/\s+/) a.each do |x| if x =~/^-[a-z0-5]+/i \ @@ -157,6 +140,10 @@ module SiSU_commandline f << pt.split[1].to_s #remove? u=/.+?\/([^\/]+)(?:(?:\/(?:en|fr|es)$)|$)/ t=/.+\/(en|fr|es)/ + lng << (pt.split[0].realpath.to_s[t,1]) \ + ? pt.split[0].realpath.to_s[t,1] \ + : nil + #: '' f_pths << { pth: pt.split[0].realpath.to_s, f: pt.split[1].to_s, @@ -176,72 +163,321 @@ module SiSU_commandline puts "#{x} in #{a.join(' ')}?" end end + { cmd: c, mod: m, what: w, paths: pth, files: f, f_pths: f_pths, lng: lng } + end + def expand_numeric_shortcuts(a) + shortcut=SiSU_Env::Info_processing_flag.new + s='' + a.each do |x| + y=case x + when /0/ + (x=~/^-1\S+/) \ + ? x.gsub(/^-0(\S+)/,shortcut.cf_0 + ' -\1') \ + : x.gsub(/^-0/,shortcut.cf_0 + ' ') + when /1/ + (x=~/^-1\S+/) \ + ? x.gsub(/^-1(\S+)/,shortcut.cf_1 + ' -\1') \ + : x.gsub(/^-1/,shortcut.cf_1 + ' ') + when /2/ + (x=~/^-2\S+/) \ + ? x.gsub(/^-2(\S+)/,shortcut.cf_2 + ' -\1') \ + : x.gsub(/^-2/,shortcut.cf_2 + ' ') + when /3/ + (x=~/^-3\S+/) \ + ? x.gsub(/^-3(\S+)/,shortcut.cf_3 + ' -\1') \ + : x.gsub(/^-3/,shortcut.cf_3 + ' ') + when /4/ + (x=~/^-4\S+/) \ + ? x.gsub(/^-4(\S+)/,shortcut.cf_4 + ' -\1') \ + : x.gsub(/^-4/,shortcut.cf_4 + ' ') + when /5/ + (x=~/^-5\S+/) \ + ? x.gsub(/^-5(\S+)/,shortcut.cf_5 + ' -\1') \ + : x.gsub(/^-5/,shortcut.cf_5 + ' ') + when /6/ + (x=~/^-6\S+/) \ + ? x.gsub(/^-6(\S+)/,shortcut.cf_5 + ' -\1') \ + : x.gsub(/^-6/,shortcut.cf_5 + ' ') + else x + end + s << " #{y}" unless y.empty? + end + s.strip! + end + def opt_cmd_and_mod_adjust(c,m) + cmd,mod,files=@cmd,@mod,@files unless m.empty? m.each do |m| case m - when /^(?:--color-toggle)$/; c=c+'c' - when /^(?:--configure)$/; c=c+'CC' - when /^(?:--dal?|--machine|--abstraction|--abs)$/; c=c+'m' - when /^(?:--txt|--text|--plaintext)$/; c=c+'t' - when /^(?:--html)$/; c=c+'h' - when /^(?:--epub)$/; c=c+'e' - when /^(?:--od[ft])$/; c=c+'o' - when /^(?:--pdf)$/; c=c+'p' - when /^(?:--concordance|--wordmap)$/; c=c+'w' - when /^(?:--manpage)$/; c=c+'i' - when /^(?:--texinfo)$/; c=c+'I' - when /^(?:--xhtml)$/; c=c+'b' - when /^(?:--xml-sax)$/; c=c+'x' - when /^(?:--xml-dom)$/; c=c+'X' - when /^(?:--digest)$/; c=c+'N' - when /^(?:--po4a|--pot?)$/; c=c+'P' - when /^(?:--termsheet)$/; c=c+'T' - when /^(?:--manifest)$/; c=c+'y' - when /^(?:--sqlite)$/; c=c+'d' - when /^(?:--pg|--pg?sql|--postgresql)$/; c=c+'D' - when /^(?:--remote|--rsync)$/; c=c+'R' - when /^(?:--scp)$/; c=c+'r' - when /^(?:--source)$/; c=c+'s' - when /^(?:--sisupod|--pod)$/; c=c+'S' - when /^(?:--git)$/; c=c+'g' - when /^(?:--urls)$/; c=c+'U' - when /^(?:--zap|--delete)$/; c=c+'Z' - when /^(?:--sample-search-form)$/; c=c+'F' - when /^(?:--webserv|--webrick)$/; c=c+'W' - when /^(?:--maintenance)$/; c=c+'M' - when /^(?:--verbose[=-]3)$/; c=c+'VM' - when /^(?:--verbose[=-]2|--Verbose|--VERBOSE)$/; c=c+'V' - when /^(?:--verbose(?:[=-]1)?)$/; c=c+'v' - when /^(?:--verbose[=-]0|--quiet|--silent)$/; c=c+'q' - else @mod << m + when /^--(?:color-toggle)$/; c=c+'c' + when /^--(?:configure)$/; c=c+'CC' + when /^--(?:dal?|machine|abstraction|abs)$/; c=c+'m' + when /^--(?:txt|text|plaintext)$/; c=c+'t' + when /^--(?:html)$/; c=c+'h' + when /^--(?:epub)$/; c=c+'e' + when /^--(?:od[ft])$/; c=c+'o' + when /^--(?:pdf)$/; c=c+'p' + when /^--(?:concordance|wordmap)$/; c=c+'w' + when /^--(?:manpage)$/; c=c+'i' + when /^--(?:texinfo)$/; c=c+'I' + when /^--(?:xhtml)$/; c=c+'b' + when /^--(?:xml-sax)$/; c=c+'x' + when /^--(?:xml-dom)$/; c=c+'X' + when /^--(?:hash-digests)$/; c=c+'N' + when /^--(?:po4a|pot?)$/; c=c+'P' + when /^--(?:termsheet)$/; c=c+'T' + when /^--(?:manifest)$/; c=c+'y' + when /^--(?:sqlite)$/; c=c+'d' + when /^--(?:pg|pg?sql|postgresql)$/; c=c+'D' + when /^--(?:remote|rsync)$/; c=c+'R' + when /^--(?:scp)$/; c=c+'r' + when /^--(?:source)$/; c=c+'s' + when /^--(?:sisupod|pod)$/; c=c+'S' + when /^--(?:git)$/; c=c+'g' + when /^--(?:urls)$/; c=c+'U' + when /^--(?:zap|delete)$/; c=c+'Z' + when /^--(?:sample-search-form)$/; c=c+'F' + when /^--(?:webserv|webrick)$/; c=c+'W' + when /^--(?:maintenance|keep-processing-files)$/; c=c+'M' + when /^--(?:verbose[=-]3)$/; c=c+'VM' + when /^--(?:verbose[=-]2|Verbose|VERBOSE)$/; c=c+'V' + when /^--(?:verbose(?:[=-]1)?)$/; c=c+'v' + when /^--(?:verbose[=-]0|quiet|silent)$/; c=c+'q' + else mod << m #mod only contains command modifiers; commands converted to character end end end + ca=[] unless c.empty? c.gsub!(/-/,'') c.scan(/CC|\S/) {|x| ca << x} - @cmd= '-' + ca.uniq.join + cmd= '-' + ca.uniq.join end - unless w.empty? ; @what=w - end - @paths = pth - @files = f - @f_pths = f_pths - if @files.length > 0 \ - and @cmd.empty? \ - and @mod.length==0 #% if no other action called on filename given, default is sisu -0 [filename(s)] configured as flag default - @cmd=shortcut.cf_0 + extra='' + if cmd !~/[mn]/ + extra+=if cmd =~/[abegHhIiNOoPpTtwXxyz]/ \ + and cmd !~/[mn]/ + 'm' #% add dal + elsif ((cmd =~/[Dd]/ \ + or (mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/)) \ + and mod.inspect !~/(?:remove|(?:(?:re)?create(?:all)?|dropall|drop)$)/) \ + and cmd !~/[mn]/ + 'm' #% add dal + else '' + end end - SiSU_Screen::Ansi.new(@cmd,"\tsisu " + @cmd + ' ' + @mod.join(' ') + ' ' + @files.join(' ') + "\n").print_brown if @cmd =~/[vVM]/ -# @files.uniq! - @fa=[] - @files.each do |f| - if f =~/\.sst$/ - elsif f =~/\.ssm$/ + if cmd !~/y/ + extra+=if cmd =~/[abeHhIiNopsSstwXxz]/ \ + and cmd !~/y/ + 'ym' #% add manifest + elsif (cmd =~/[Dd]/ \ + or mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/) \ + and files[0] !~/^remove$/ \ + and cmd !~/y/ + 'ym' #% add manifest + else '' end end - @files - self + cmd=cmd + extra + cmds=cmd.scan(/CC|\S/) + [cmds.uniq.join,mod] + end + def opt_act #note mod line commands have already been converted to command characters, cmd + cmd,mod=@cmd,@mod + act={} + act[:license]=if cmd =~/L/ \ + or mod.inspect =~/"--license/ + true + else false + end + act[:site_init]=if cmd =~/C/ \ + or mod.inspect =~/"--init-site/ + true + else false + end + act[:verbose]=if cmd =~/v/ \ + or mod.inspect =~/"--verbose"/ + true + else false + end + act[:quiet]=if cmd =~/q/ \ + or mod.inspect =~/"--quiet"/ + true + else false + end + act[:color_state]=if mod.inspect =~/"--color-on"|"--color"/ + true + elsif mod.inspect =~/"--color-off"/ + true + else true #fix default color + end +# act[:color_toggle]=if cmd =~/c/ \ +# or mod.inspect =~/"--color-toggle"/ +# true +# else false +# end + act[:maintenance]=if cmd =~/M/ \ + or mod.inspect =~/"--maintenance|--keep-processing-files"/ + true + else false + end + act[:ocn]=if mod.inspect =~/"--no-ocn"/ + false + else true + end + act[:dal]=if cmd =~/m/ \ + or mod.inspect =~/"--dal"/ + true + else false + end + act[:html]=if cmd =~/h/ \ + or mod.inspect =~/"--html"/ + true + else false + end + act[:concordance]=if cmd =~/w/ \ + or mod.inspect =~/"--concordance"/ + true + else false + end + act[:pdf]=if cmd =~/p/ \ + or mod.inspect =~/"--pdf"/ + true + else false + end + act[:epub]=if cmd =~/e/ \ + or mod.inspect =~/"--epub"/ + true + else false + end + act[:odt]=if cmd =~/o/ \ + or mod.inspect =~/"--odf"/ + true + else false + end + act[:xml_sax]=if cmd =~/x/ \ + or mod.inspect =~/"--xml-sax"/ + true + else false + end + act[:xml_dom]=if cmd =~/X/ \ + or mod.inspect =~/"--xml-dom"/ + true + else false + end + act[:xhtml]=if cmd =~/b/ \ + or mod.inspect =~/"--xhtml"/ + true + else false + end + act[:txt]=if cmd =~/[at]/ \ + or mod.inspect =~/"--txt"/ + true + else false + end + act[:manpage]=if cmd =~/i/ \ + or mod.inspect =~/"--manpage"/ + true + else false + end + act[:texinfo]=if cmd =~/I/ \ + or mod.inspect =~/"--texinfo"/ + true + else false + end + act[:fictionbook]=if cmd =~/f/ \ + or mod.inspect =~/"--fictionbook"/ + true + else false + end + act[:psql]=if cmd =~/D/ \ + or mod.inspect =~/"--pg"|"--pgsql"/ + true + else false + end + act[:sqlite]=if cmd =~/d/ \ + or mod.inspect =~/"--sqlite"/ + true + else false + end + act[:harvest]=if mod.inspect =~/"--harvest"/ + true + else false + end + act[:po4a]=if mod.inspect =~/"--po4a"|"--po"/ + true + else false + end + act[:git]=if cmd =~/g/ \ + or mod.inspect =~/"--git"/ + true + else false + end + act[:hash_digests]=if cmd =~/N/ \ + or mod.inspect =~/"--hash-digests"/ + true + else false + end + act[:sample_search_form]=if cmd =~/F/ \ + or mod.inspect =~/"--sample-search-form"/ + true + else false + end + act[:webrick]=if cmd =~/W/ \ + or mod.inspect =~/"--webrick"/ + true + else false + end + act[:share_source]=if cmd =~/s/ \ + or mod.inspect =~/"--source"/ + true + else false + end + act[:sisupod]=if cmd =~/S/ \ + or mod.inspect =~/"--sisupod"/ + true + else false + end + act[:scp]=if cmd =~/r/ \ + or mod.inspect =~/"--scp"/ + true + else false + end + act[:rsync]=if cmd =~/R/ \ + or mod.inspect =~/"--rsync"/ + true + else false + end + act[:delete_output]=if cmd =~/z/ \ + or mod.inspect =~/"--delete"|"--zap"/ + true + else false + end + act[:urls_all]=if cmd =~/U/ \ + or mod.inspect =~/"--urls-all"/ + true + else false + end + act[:urls_seleted]=if cmd =~/u/ \ + or mod.inspect =~/"--urls"/ + true + else false + end + act[:sitemap]=if cmd =~/Y/ \ + or mod.inspect =~/"--sitemap"/ + true + else false + end + act[:manifest]=if cmd =~/y/ \ + or mod.inspect =~/"--manifest"/ + true + else false + end + act[:help]=if mod.inspect =~/"--help/ + true + else false + end + @act=act end def cmd @cmd @@ -249,12 +485,18 @@ module SiSU_commandline def mod @mod end + def act + @act + end def f_pth @f_pth end def pth @pth end + def lng + @lng + end def fns @fns end |