aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2011-06-08 22:00:27 -0400
committerRalph Amissah <ralph@amissah.com>2011-06-08 22:06:00 -0400
commit7bf74c7fb5d70b4880c11f782c07cf9e78127779 (patch)
tree91d7874287e60ecfac780251a917c3fdc2ba5b62 /lib
parentv2 v3: help, s/Bul garian/Bulgarian/ (Closes: #619068) (diff)
v3: options, restrict glob rule checks to glob & find; carry lang info
* restrict glob rule checks to when --glob (-G) or --find (-f) requested * carry information on document language (from filename and or directory) * (additional test)
Diffstat (limited to 'lib')
-rw-r--r--lib/sisu/v3/options.rb111
1 files changed, 61 insertions, 50 deletions
diff --git a/lib/sisu/v3/options.rb b/lib/sisu/v3/options.rb
index 96ec3c4a..81d12db8 100644
--- a/lib/sisu/v3/options.rb
+++ b/lib/sisu/v3/options.rb
@@ -62,14 +62,17 @@ module SiSU_commandline
require_relative 'sysenv' # sysenv.rb
@@base_path=nil
class Options
- attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:base_path,:paths,:lngs,:f_pth,:pth,:fns,:fnb,:fnc,:fncb,:lng,:what
+ attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:base_path,:base_stub,:paths,:lngs,:f_pth,:pth,:fns,:fnb,:fnc,:fncb,:lng,:what
def initialize(a)
- @cmd,@f_pth,@pth,@fns,@fnb,@fnc,@fncb,@what,@lng,@base_path='','','','','','','','','','',''
+ @cmd,@f_pth,@pth,@fns,@fnb,@fnc,@fncb,@what,@lng,@base_path,@base_stub='','','','','','','','','','','',''
@f_pths,@files,@paths,@mod,@act=Array.new(5){[]}
@env=SiSU_Env::Info_env.new
@dir_structure_by=SiSU_Env::Env_call.new.output_dir_structure.by?
@@base_path ||=Dir.pwd
@base_path=@@base_path
+ r=Px[:lng_lst].join('|')
+ u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/
+ @base_stub=@base_path.gsub(u,'\1')
@a=sisu_glob_rules(a)
@a.freeze
init
@@ -97,7 +100,6 @@ module SiSU_commandline
else
Dir.glob("*#{g}*.ss[tm]")
end
-
Px[:lng_lst].each do |d|
if FileTest.directory?(d)
x <<=if g =~/.ss[tm]/
@@ -113,40 +115,40 @@ module SiSU_commandline
end
end
def sisu_glob_rules(a)
- b=[]
- f=[]
- find_flag=false
- a.each do |y|
- if y =~ /^-/ \
- or y =~ /\.ss[tm]$/
- if y =~/^-/ \
- && y =~/[fG]|--find|--glob/
- find_flag=true
+ a=if a.inspect =~/"-\S*[fG]/ \
+ or a.inspect =~/"--find"|"--glob"/
+ b,f=[],[]
+ find_flag=false
+ a.each do |y|
+ if y =~ /^-/
+ if y =~/^-/ \
+ && y =~/[fG]|--find|--glob/
+ find_flag=true
+ end
+ b << y
+ end
+ if find_flag \
+ && y !~ /^-/ \
+ && y =~ /\S+/
+ f << y
end
- b << y
- end
- if find_flag \
- && y !~ /^-/ \
- && y =~ /\S+/
- f << y
- elsif y =~ /^-/
- b << y
end
- end
- r=Px[:lng_lst].join('|')
- r.gsub!(/\|en\|/,'|')
- @lang_regx=%r{(?:#{r})}
- z=if find_flag
- if f.length > 0
- b + find_select(find_flag,f)
- else
- find_all(find_flag,b)
+ r=Px[:lng_lst].join('|')
+ r.gsub!(/\|en\|/,'|')
+ @lang_regx=%r{(?:#{r})}
+ z=if find_flag
+ if f.length > 0
+ b + find_select(find_flag,f)
+ else
+ find_all(find_flag,b)
+ end
+ elsif a.inspect =~/"(?:-\S+?|--\S+?)"/ \
+ && a.inspect =~/"#{@lang_regx}\/?"/ \
+ && a.inspect =~/"en\/\S+?\.ss[tm]"/
+ init_selected_lang_dirs(a)
+ else b
end
- elsif a.inspect =~/"(?:-\S+?|--\S+?)"/ \
- && a.inspect =~/"#{@lang_regx}\/?"/ \
- && a.inspect =~/"en\/\S+?\.ss[tm]"/
- init_selected_lang_dirs(a)
- else b
+ else a
end
end
def init_selected_lang_dirs(a)
@@ -164,20 +166,22 @@ module SiSU_commandline
end
def init
a=@a
- 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]
- @lngs = q[:lngs]
- 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
- SiSU_Screen::Ansi.new(@cmd,"\tsisu " + @cmd + ' ' + @mod.join(' ') + ' ' + @files.join(' ') + "\n").print_brown if @cmd =~/[vVM]/
+ if a.length > 0
+ 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]
+ @lngs = q[:lngs]
+ 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
+ SiSU_Screen::Ansi.new(@cmd,"\tsisu " + @cmd + ' ' + @mod.join(' ') + ' ' + @files.join(' ') + "\n").print_brown if @cmd =~/[vVM]/
+ end
# @files.uniq!
@act=opt_act
@files
@@ -187,7 +191,7 @@ module SiSU_commandline
c,w='',''
m,f,pth,z,lng,lngs=[],[],[],[],[],[]
a=s.split(/\s+/)
- a.each do |x|
+ a.uniq.each do |x|
if x =~/^-[a-z0-5]+/i \
or x =~/^--\S+/
if x =~/^-([a-z0-5]+)/i; c << $1
@@ -215,13 +219,20 @@ module SiSU_commandline
$1
else 'en'
end
+ lng_is =if l_p
+ l_p
+ elsif x =~/~(#{r})\.ss[tm]/
+ $1
+ else 'en'
+ end
f_pths << {
pth: pt.split[0].realpath.to_s,
f: pt.split[1].to_s,
pth_stub: pt.split[0].realpath.to_s[u,1],
lng: (pt.split[0].realpath.to_s[t,1]) \
? pt.split[0].realpath.to_s[t,1] \
- : nil
+ : nil,
+ lng_is: lng_is
}
# Dir.chdir(pt.split[0].realpath)
else puts "file not found: #{x}"