Module: Metanorma::Cli
- Defined in:
- lib/metanorma/cli.rb,
lib/metanorma/cli/ui.rb,
lib/metanorma/cli/errors.rb,
lib/metanorma/cli/command.rb,
lib/metanorma/cli/version.rb,
lib/metanorma/cli/compiler.rb,
lib/metanorma/cli/generator.rb,
lib/metanorma/cli/git_template.rb,
lib/metanorma/cli/template_repo.rb,
lib/metanorma/cli/commands/template_repo.rb
Defined Under Namespace
Modules: Commands, Errors
Classes: Command, Compiler, Generator, GitTemplate, TemplateRepo, UI
Constant Summary
collapse
- SUPPORTED_GEMS =
[
"metanorma-iso",
"metanorma-ietf",
"metanorma-gb",
"metanorma-csd",
"metanorma-csand",
"metanorma-m3d",
"metanorma-acme",
"metanorma-standoc",
"metanorma-unece",
"metanorma-nist",
"metanorma-ogc",
"metanorma-itu"
]
- PRIVATE_SUPPORTED_GEMS =
["metanorma-rsd", "metanorma-mpfd"]
- VERSION =
"1.2.4"
Class Method Summary
collapse
Class Method Details
.base_templates_path ⇒ Object
70
71
72
|
# File 'lib/metanorma/cli.rb', line 70
def self.base_templates_path
root_path.join("templates", "base")
end
|
.find_command(arguments) ⇒ Object
96
97
98
99
|
# File 'lib/metanorma/cli.rb', line 96
def self.find_command(arguments)
commands = Metanorma::Cli::Command.all_commands.keys
commands.select { |cmd| arguments.include?(cmd.gsub("_", "-")) == true }
end
|
.home_directory ⇒ Object
78
79
80
|
# File 'lib/metanorma/cli.rb', line 78
def self.home_directory
Pathname.new(Dir.home).join(".metanorma")
end
|
.load_all_flavors ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/metanorma/cli.rb', line 37
def self.load_all_flavors
flavor_names = Gem::Specification.find_all do |g|
g.name =~ /\Ametanorma-.*\Z/
end.map(&:name)
load_flavors(flavor_names)
end
|
.load_flavors(flavor_names = SUPPORTED_GEMS + PRIVATE_SUPPORTED_GEMS) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/metanorma/cli.rb', line 25
def self.load_flavors(flavor_names = SUPPORTED_GEMS + PRIVATE_SUPPORTED_GEMS)
flavor_names.each do |flavor|
begin
require flavor
rescue LoadError
unless PRIVATE_SUPPORTED_GEMS.include?(flavor)
$stderr.puts "[metanorma] Error: flavor gem #{flavor} not present"
end
end
end
end
|
.root ⇒ Object
66
67
68
|
# File 'lib/metanorma/cli.rb', line 66
def self.root
File.dirname(__dir__)
end
|
.root_path ⇒ Object
92
93
94
|
# File 'lib/metanorma/cli.rb', line 92
def self.root_path
Pathname.new(Cli.root).join("..")
end
|
.start(arguments) ⇒ Object
Invoking commands
In the Metanorma CLI, we’ve included some custom behavior, like exposing the compiation directly from the root command.
So, for this use case we first check if the user is actually trying to compile a document or not, and based on that we’ll compile the document or show the help documentation.
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/metanorma/cli.rb', line 54
def self.start(arguments)
if find_command(arguments).empty?
arguments.unshift("compile")
end
Metanorma::Cli::Command.start(arguments)
rescue Errors::FileNotFoundError => error
UI.say("Error: #{error}, \nNot sure what to run? try: metanorma help")
exit(Errno::ENOENT::Errno)
end
|
.templates_path ⇒ Object
74
75
76
|
# File 'lib/metanorma/cli.rb', line 74
def self.templates_path
home_directory.join("templates")
end
|
.writable_templates_path? ⇒ Boolean
82
83
84
85
86
87
88
89
90
|
# File 'lib/metanorma/cli.rb', line 82
def self.writable_templates_path?
parent_directory = templates_path.join("..", "..")
unless parent_directory && parent_directory.writable?
raise Errno::EACCES, "No permission to write in this drectory"
end
return true
end
|