Class: Metanorma::Cli::Command

Inherits:
ThorWithConfig show all
Defined in:
lib/metanorma/cli/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/metanorma/cli/command.rb', line 210

def self.exit_on_failure?
  true
end

Instance Method Details

#collection(filename = nil) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/metanorma/cli/command.rb', line 111

def collection(filename = nil)
  if filename
    coll_options = options.dup
    coll_options[:compile] = filter_compile_options(coll_options)
    Metanorma::Cli::Collection.render(filename, coll_options)
  else
    UI.say("Need to specify a file to process")
  end
rescue ArgumentError => e
  UI.say e.message
end

#compile(file_name = nil) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/AbcSize



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/metanorma/cli/command.rb', line 73

def compile(file_name = nil)
  if file_name && !options[:version]
    documents = select_wildcard_documents(file_name) || [file_name]
    documents.each { |document| compile_document(document, options.dup) }

  elsif options[:version]
    invoke(:version, [], type: options[:type], format: options[:format])

  elsif options[:log_messages]
    invoke(:log_messages, [], type: options[:type], agree_to_terms: true)

  elsif options.keys.size >= 2
    UI.say("Need to specify a file to process")

  else
    invoke :help
  end
end

#convert(inputfile) ⇒ Object



147
148
149
150
151
# File 'lib/metanorma/cli/command.rb', line 147

def convert(inputfile)
  MnConvert.convert(inputfile, options)
rescue Error => e
  UI.say e.message
end

#list_doctypes(type = nil) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/metanorma/cli/command.rb', line 191

def list_doctypes(type = nil)
  processors = backend_processors

  if type && processors[type.to_sym]
    processors = { type.to_sym => processors[type.to_sym] }
  end

  print_doctypes_table(processors)
end

#list_extensions(type = nil) ⇒ Object



184
185
186
187
188
# File 'lib/metanorma/cli/command.rb', line 184

def list_extensions(type = nil)
  single_type_extensions(type) || all_type_extensions
rescue LoadError
  UI.say("Couldn't load #{type}, please provide a valid type!")
end

#log_messagesObject



171
172
173
174
175
176
177
178
179
180
181
# File 'lib/metanorma/cli/command.rb', line 171

def log_messages
  if options[:type]
    Metanorma::Cli.load_flavors
    messages = ::Metanorma::Compile.new.extract_log_messages(options[:type])
    UI.say(messages)
  else
    UI.say("Please specify a standard type with -t option")
  end
rescue NameError => e
  UI.say(e)
end

#new(name) ⇒ Object



28
29
30
# File 'lib/metanorma/cli/command.rb', line 28

def new(name)
  create_new_document(name, options)
end

#versionObject



159
160
161
162
163
164
165
# File 'lib/metanorma/cli/command.rb', line 159

def version
  Metanorma::Cli.load_flavors
  backend_version(options[:type]) || supported_backends
  options[:type] or dependencies_versions
rescue NameError => e
  UI.say(e)
end