Class: SublimeDSL::CLI::Import
- Inherits:
-
Object
- Object
- SublimeDSL::CLI::Import
- Defined in:
- lib/sublime_dsl/cli/import.rb
Instance Attribute Summary collapse
-
#importer ⇒ Object
readonly
Returns the value of attribute importer.
-
#main_cmd ⇒ Object
readonly
Returns the value of attribute main_cmd.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Class Method Summary collapse
Instance Method Summary collapse
- #error(msg) ⇒ Object
- #help ⇒ Object
-
#initialize(main_cmd) ⇒ Import
constructor
A new instance of Import.
- #parse_options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(main_cmd) ⇒ Import
Returns a new instance of Import.
13 14 15 |
# File 'lib/sublime_dsl/cli/import.rb', line 13 def initialize(main_cmd) @main_cmd = main_cmd end |
Instance Attribute Details
#importer ⇒ Object (readonly)
Returns the value of attribute importer.
11 12 13 |
# File 'lib/sublime_dsl/cli/import.rb', line 11 def importer @importer end |
#main_cmd ⇒ Object (readonly)
Returns the value of attribute main_cmd.
10 11 12 |
# File 'lib/sublime_dsl/cli/import.rb', line 10 def main_cmd @main_cmd end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
11 12 13 |
# File 'lib/sublime_dsl/cli/import.rb', line 11 def writer @writer end |
Class Method Details
.summary ⇒ Object
6 7 8 |
# File 'lib/sublime_dsl/cli/import.rb', line 6 def self.summary "convert a Sublime Text package to a set of DSL source files" end |
Instance Method Details
#error(msg) ⇒ Object
29 30 31 |
# File 'lib/sublime_dsl/cli/import.rb', line 29 def error(msg) raise OptionError, msg end |
#help ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/sublime_dsl/cli/import.rb', line 83 def help <<-HELP.dedent Usage: #{main_cmd.name} import <package> [options] <package> The name of a Sublime Text package directory containing files to convert to DSL files. Options: -s, --source PATH The path to the directory containing the directory <package>. By default, it is the Sublime Text Packages directory. -i, --include PATTERNS Files to process or copy. By default, all files are processed (except the files defined by the --exclude option). PATTERNS must be a list of specifications separated by semicolons, for instance "*.tmSnippet;*.tmLanguage". -e, --exclude PATTERNS Files not to process nor copy. By default "*.cache;*.pyc". -t, --target PATH The path to the target root directory: generated DSL files will be placed there in a subdirectory named <package>. By default, it is the current directory. -k, --keyboard NAME Convert keymap definitions for keyboard NAME. By default, no keymap conversion is done. A file NAME.keyboard.rb will be searched for in the subdirectories of <target_path>. -r, --recognized Do not copy non-recognized files to the target directory. By default, non-recognized files (e.g., Python scripts) are copied "as is" from the source directory to the target directory. -b, --backup [POLICY] Define the backup policy if the directory <target_path>/<package> already exists and contains files. POLICY may be: never: do not create a backup always: always create a backup once: create a backup if there is not already one Not giving a policy (-b or --backup alone) is the same as 'always'. The default is 'once'. The backup will be a zip file placed in <target_path>, named <package_name>.<time_stamp>.zip -q, --quiet Do not report any information or warning. -V, --verbose Report detailed progress information. HELP end |
#parse_options ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sublime_dsl/cli/import.rb', line 33 def package_name = ARGV.shift error 'missing package name' unless package_name @importer = SublimeText::Package::Importer.new(package_name) @writer = SublimeText::Package::Writer.new while (option = ARGV.shift) case option when '-s', '--source' path = ARGV.shift path or error "#{option}: missing path" importer.root = path when '-i', '--include' pattern = ARGV.shift pattern or error "#{option}: missing pattern" importer.include = pattern when '-e', '--exclude' pattern = ARGV.shift pattern or error "#{option}: missing pattern" importer.exclude = pattern when '-t', '--target' path = ARGV.shift path or error "#{option}: missing path" writer.root = path when '-k', '--keyboard' keyboard = ARGV.shift keyboard or error "#{option}: missing keyboard" writer.keyboard = keyboard when '-r', '--recognized' writer.copy_other_files = false when '-b', '--backup' policy = ARGV.shift case policy when nil policy = :always when /^-/ ARGV.unshift policy policy = :always end writer.backup = policy when '-q', '--quiet' Console.verbosity = 0 when '-V', '--verbose' Console.verbosity = 2 else error "invalid argument: #{option.inspect}" end end ARGV.empty? or error "invalid arguments: #{ARGV.join(' ')}" end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sublime_dsl/cli/import.rb', line 17 def run package = importer.package exit 1 unless package writer.write package exit rescue OptionError => ex Console.error ex. Console.error %(type "#{main_cmd.name} help import" for more information) exit 2 end |