Class: Metanorma::Cli::Command

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

Instance Method Summary collapse

Instance Method Details

#collection(filename = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/metanorma/cli/command.rb', line 65

def collection(filename = nil)
  if filename
    opts = options
    opts[:format] &&= opts[:format].split(",").map &:to_sym
    opts[:compile] = filter_compile_options(opts)
    coll = Metanorma::Collection.parse filename
    coll.render opts
  else UI.say("Need to specify a file to process")
  end
rescue ArgumentError => e
  UI.say e.message
end

#compile(file_name = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/metanorma/cli/command.rb', line 40

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.keys.size >= 2
    UI.say("Need to specify a file to process")

  else
    invoke :help
  end
end

#list_doctypes(type = nil) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/metanorma/cli/command.rb', line 97

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



90
91
92
93
94
# File 'lib/metanorma/cli/command.rb', line 90

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

#new(name) ⇒ Object



19
20
21
# File 'lib/metanorma/cli/command.rb', line 19

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

#versionObject



82
83
84
85
86
87
# File 'lib/metanorma/cli/command.rb', line 82

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