Class: SublimeDSL::CLI::Export
- Inherits:
-
Object
- Object
- SublimeDSL::CLI::Export
- Defined in:
- lib/sublime_dsl/cli/export.rb
Instance Attribute Summary collapse
-
#exporter ⇒ Object
readonly
Returns the value of attribute exporter.
-
#main_cmd ⇒ Object
readonly
Returns the value of attribute main_cmd.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Class Method Summary collapse
Instance Method Summary collapse
- #error(msg) ⇒ Object
- #help ⇒ Object
-
#initialize(main_cmd) ⇒ Export
constructor
A new instance of Export.
- #parse_options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(main_cmd) ⇒ Export
Returns a new instance of Export.
13 14 15 |
# File 'lib/sublime_dsl/cli/export.rb', line 13 def initialize(main_cmd) @main_cmd = main_cmd end |
Instance Attribute Details
#exporter ⇒ Object (readonly)
Returns the value of attribute exporter.
11 12 13 |
# File 'lib/sublime_dsl/cli/export.rb', line 11 def exporter @exporter end |
#main_cmd ⇒ Object (readonly)
Returns the value of attribute main_cmd.
10 11 12 |
# File 'lib/sublime_dsl/cli/export.rb', line 10 def main_cmd @main_cmd end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
11 12 13 |
# File 'lib/sublime_dsl/cli/export.rb', line 11 def reader @reader end |
Class Method Details
.summary ⇒ Object
6 7 8 |
# File 'lib/sublime_dsl/cli/export.rb', line 6 def self.summary "convert a set of DSL source files to a Sublime Text package" end |
Instance Method Details
#error(msg) ⇒ Object
29 30 31 |
# File 'lib/sublime_dsl/cli/export.rb', line 29 def error(msg) raise OptionError, msg end |
#help ⇒ Object
79 80 81 82 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 |
# File 'lib/sublime_dsl/cli/export.rb', line 79 def help " Usage: \#{main_cmd.name} export <package> [options]\n\n <package>\n The name of a directory containing the DSL files to process.\n\n Options:\n -s, --source PATH\n The path to the directory containing the directory <package>.\n By default, it is the current directory.\n\n -i, --include PATTERNS\n Files to process or copy. By default, all files are processed\n (except the files defined by the --exclude option).\n PATTERNS must be a list of specifications separated by semicolons,\n for instance \"*.rb;*.py\".\n\n -e, --exclude PATTERNS\n Files not to process nor copy. By default \"*.keyboard.rb\"\n (keyboard definition files are processed when called from\n keymap definitions).\n\n -t, --target PATH\n The path to the target root directory: the generated files\n will be placed there in a subdirectory named <package>.\n By default, it is the Sublime Text Packages directory.\n\n -b, --backup [POLICY]\n Define the backup policy if the directory <target_path>/<package>\n already exists and contains files. POLICY may be:\n never: do not create a backup\n always: always create a backup\n once: create a backup if there is not already one\n Not giving a policy (-b or --backup alone) is the same\n as 'always'. The default is 'always'.\n The backup will be a zip file placed in <target_path>,\n named <package_name>.<time_stamp>.zip\n\n -c, --cleanup\n Delete any file in the directory <target_path>/<package>\n that is not generated by the export process. By default,\n no file is removed from the target directory.\n\n -q, --quiet\n Do not report any information or warning.\n\n -V, --verbose\n Report detailed progress information.\n HELP\nend\n".dedent |
#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 |
# File 'lib/sublime_dsl/cli/export.rb', line 33 def package_name = ARGV.shift error 'missing package name' unless package_name @reader = SublimeText::Package::Reader.new(package_name) @exporter = SublimeText::Package::Exporter.new while (option = ARGV.shift) case option when '-s', '--source' path = ARGV.shift path or error "#{option}: missing path" reader.root = path when '-i', '--include' pattern = ARGV.shift pattern or error "#{option}: missing pattern" reader.include = pattern when '-e', '--exclude' pattern = ARGV.shift pattern or error "#{option}: missing pattern" reader.exclude = pattern when '-t', '--target' path = ARGV.shift path or error "#{option}: missing path" exporter.root = path when '-b', '--backup' policy = ARGV.shift case policy when nil policy = :always when /^-/ ARGV.unshift policy policy = :always end exporter.backup = policy when '-c', '--cleanup' exporter.cleanup = true 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/export.rb', line 17 def run package = reader.package exit 1 unless package exporter.export package exit rescue OptionError => ex Console.error ex. Console.error %(type "#{main_cmd.name} help export" for more information) exit 2 end |