Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b73441
commit d5f7bcd
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
add_subdirectory(ruby) | ||
add_subdirectory(binary) | ||
|
||
|
||
|
||
install(PROGRAMS y2base/y2base DESTINATION lib/YaST2/bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module Yast | ||
module Y2Base | ||
|
||
# Parses ARGV of y2base. it returns map with keys: | ||
# | ||
# - :generic_options [Hash] | ||
# - :client_name [String, nil] | ||
# - :client_options [Hash] | ||
# - :server_name [String, nil] | ||
# - :server_options [Array] ( of unparsed options as server parse it on its own) | ||
# @raise RuntimeError when unknown option appear or used wrongly | ||
def self.parse_arguments(args) | ||
ret = {} | ||
|
||
ret[:generic_options] = parse_generic_options(args) | ||
ret[:client_name] = args.shift | ||
ret[:client_options] = parse_client_options(args) | ||
ret[:server_name] = args.shift | ||
ret[:server_options] = args | ||
|
||
ret | ||
end | ||
|
||
private_class_method def self.parse_generic_options(args) | ||
res = {} | ||
loop do | ||
return res unless option?(args.first) | ||
|
||
raise "Unknown option #{args.first}" | ||
end | ||
end | ||
|
||
private_class_method def self.parse_client_options(args) | ||
res = {} | ||
string_param = false | ||
params = [] | ||
loop do | ||
return res unless option?(args.first) | ||
|
||
arg = args.shift | ||
case arg | ||
when "-S" | ||
string_param = true | ||
when /^\(/ | ||
raise "Only string client parameters supported" unless string_param | ||
|
||
params << arg[1..-1] | ||
else | ||
raise "Unknown option #{arg}" | ||
end | ||
end | ||
res[:params] = params | ||
|
||
res | ||
end | ||
|
||
private_class_method def self.option?(arg) | ||
return true if arg[0] == "-" | ||
return true if arg[0] == "(" && arg[-1] == ")" | ||
|
||
return false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters