Class: XcodeAssetsGen::CLI
- Inherits:
-
Object
- Object
- XcodeAssetsGen::CLI
- Defined in:
- lib/xcode_assets_gen.rb
Instance Method Summary collapse
-
#cli_flags ⇒ Object
set up defaults in its own method.
- #main(command_line_options = "") ⇒ Object
- #parse_arguments(command_line_options, parser) ⇒ Object
Instance Method Details
#cli_flags ⇒ Object
set up defaults in its own method
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/xcode_assets_gen.rb', line 12 def cli_flags = Slop::Options.new pwd = Dir.pwd . = "usage: tubes [options] ..." .string "-i", "--icon", "Set icon path, default is ./icon.png", default: File.join(pwd, "icon.png") .string "-l", "--launch_image_path", "Set launch image path, default is current path", default: pwd .string "-o", "--output", "Set output file path, default is ./Assets.xcassets", default: File.join(pwd, "Assets.xcassets") .string "-s", "--icon_set_list", "Set icon set list, default: ['ipad-ios7+', 'iphone-ios7+']", default: ['ipad-ios7+', 'iphone-ios7+'] end |
#main(command_line_options = "") ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/xcode_assets_gen.rb', line 42 def main(="") parser = Slop::Parser.new cli_flags arguments = parse_arguments(, parser) # --ip is a boolean, it is set to false even if left off by slop icon_path = arguments.fetch(:icon) launch_image_path = arguments.fetch(:launch_image_path) output = arguments.fetch(:output) icon_set_list = arguments.fetch(:icon_set_list) XcodeAssetsGen::IconGen.new.gen_icons(icon_set_list, output, icon_path) XcodeAssetsGen::LaunchImageGen.new.gen_launch_images(output, launch_image_path) XcodeAssetsGen.gen_top_contents_json(output) end |
#parse_arguments(command_line_options, parser) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xcode_assets_gen.rb', line 23 def parse_arguments(, parser) begin # slop has the advantage over optparse that it can do strings and not just ARGV result = parser.parse result.to_hash # Very important to not bury this begin/rescue logic in another method # otherwise it will be difficult to check to see if -h or --help was passed # in this case -h acts as an unknown option as long as we don't define it # in cli_flags. rescue Slop::UnknownOption # print help puts cli_flags exit # If, for your program, you can't exit here, then reraise Slop::UnknownOption # raise a custom exception, push the rescue up to main or track that "help was invoked" end end |