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/collection.rb,
lib/metanorma/cli/git_template.rb,
lib/metanorma/cli/commands/site.rb,
lib/metanorma/cli/template_repo.rb,
lib/metanorma/cli/site_generator.rb,
lib/metanorma/cli/commands/config.rb,
lib/metanorma/cli/thor_with_config.rb,
lib/metanorma/cli/commands/template_repo.rb
Defined Under Namespace
Modules: Commands, Errors
Classes: Collection, Command, Compiler, Generator, GitTemplate, SiteGenerator, TemplateRepo, ThorWithConfig, UI
Constant Summary
collapse
- CONFIG_DIRNAME =
".metanorma"
- CONFIG_FILENAME =
"config.yml"
- VERSION =
"1.12.6".freeze
Class Method Summary
collapse
Class Method Details
.base_templates_path ⇒ Object
49
50
51
|
# File 'lib/metanorma/cli.rb', line 49
def self.base_templates_path
root_path.join("templates", "base")
end
|
.config_path(global: false) ⇒ Object
69
70
71
72
73
|
# File 'lib/metanorma/cli.rb', line 69
def self.config_path(global: false)
return global_config_path if global
local_config_path
end
|
.find_command(arguments) ⇒ Object
93
94
95
96
|
# File 'lib/metanorma/cli.rb', line 93
def self.find_command(arguments)
commands = Metanorma::Cli::Command.all_commands.keys
commands.select { |cmd| arguments.include?(cmd.tr("_", "-")) == true }
end
|
.global_config_path ⇒ Object
61
62
63
|
# File 'lib/metanorma/cli.rb', line 61
def self.global_config_path
home_directory.join(CONFIG_FILENAME)
end
|
.home_directory ⇒ Object
57
58
59
|
# File 'lib/metanorma/cli.rb', line 57
def self.home_directory
Pathname.new(Dir.home).join(CONFIG_DIRNAME)
end
|
.local_config_path ⇒ Object
.print_fatal_summary(error) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/metanorma/cli.rb', line 98
def self.print_fatal_summary(error)
$stdout.flush
$stderr.flush
UI.error(error.message)
exit(-1)
end
|
.root ⇒ Object
45
46
47
|
# File 'lib/metanorma/cli.rb', line 45
def self.root
File.dirname(__dir__)
end
|
.root_path ⇒ Object
85
86
87
|
# File 'lib/metanorma/cli.rb', line 85
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.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/metanorma/cli.rb', line 30
def self.start(arguments)
if find_command(arguments).empty?
arguments.unshift("compile")
end
Metanorma::Cli::Command.start(arguments)
rescue SignalException UI.say("Process cancelled, exiting.")
rescue Errors::FileNotFoundError => e
UI.say("Error: #{e}. \nNot sure what to run? try: metanorma help")
exit(Errno::ENOENT::Errno)
rescue Errors::FatalCompilationError => e
print_fatal_summary(e)
end
|
.templates_path ⇒ Object
53
54
55
|
# File 'lib/metanorma/cli.rb', line 53
def self.templates_path
home_directory.join("templates")
end
|
.with_indifferent_access(options) ⇒ Object
89
90
91
|
# File 'lib/metanorma/cli.rb', line 89
def self.with_indifferent_access(options)
Thor::CoreExt::HashWithIndifferentAccess.new(options)
end
|
.writable_templates_path? ⇒ Boolean
75
76
77
78
79
80
81
82
83
|
# File 'lib/metanorma/cli.rb', line 75
def self.writable_templates_path?
parent_directory = templates_path.join("..", "..")
unless parent_directory&.writable?
raise Errno::EACCES, "No permission to write in this directory"
end
true
end
|