Class: SublimeDSL::CLI::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/sublime_dsl/cli/export.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#exporterObject (readonly)

Returns the value of attribute exporter.



11
12
13
# File 'lib/sublime_dsl/cli/export.rb', line 11

def exporter
  @exporter
end

#main_cmdObject (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

#readerObject (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

.summaryObject



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

Raises:



29
30
31
# File 'lib/sublime_dsl/cli/export.rb', line 29

def error(msg)
  raise OptionError, msg
end

#helpObject



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_optionsObject



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 parse_options
  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

#runObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sublime_dsl/cli/export.rb', line 17

def run
  parse_options
  package = reader.package
  exit 1 unless package
  exporter.export package
  exit
rescue OptionError => ex
  Console.error ex.message
  Console.error %(type "#{main_cmd.name} help export" for more information)
  exit 2
end