module Metanorma::Cli
Constants
- CONFIG_DIRNAME
- CONFIG_FILENAME
- VERSION
Public Class Methods
base_templates_path()
click to toggle source
# File lib/metanorma/cli.rb, line 45 def self.base_templates_path root_path.join("templates", "base") end
config_path(global = false)
click to toggle source
# File lib/metanorma/cli.rb, line 65 def self.config_path(global = false) return global_config_path if global local_config_path end
find_command(arguments)
click to toggle source
# File lib/metanorma/cli.rb, line 85 def self.find_command(arguments) commands = Metanorma::Cli::Command.all_commands.keys commands.select { |cmd| arguments.include?(cmd.gsub("_", "-")) == true } end
global_config_path()
click to toggle source
# File lib/metanorma/cli.rb, line 57 def self.global_config_path home_directory.join(CONFIG_FILENAME) end
home_directory()
click to toggle source
# File lib/metanorma/cli.rb, line 53 def self.home_directory Pathname.new(Dir.home).join(CONFIG_DIRNAME) end
load_flavors()
click to toggle source
# File lib/metanorma/cli.rb, line 16 def self.load_flavors Metanorma::Flavor.load_flavors end
local_config_path()
click to toggle source
# File lib/metanorma/cli.rb, line 61 def self.local_config_path Pathname.new(Dir.pwd).join(CONFIG_DIRNAME, CONFIG_FILENAME) end
root()
click to toggle source
# File lib/metanorma/cli.rb, line 41 def self.root File.dirname(__dir__) end
root_path()
click to toggle source
# File lib/metanorma/cli.rb, line 81 def self.root_path Pathname.new(Cli.root).join("..") end
start(arguments)
click to toggle source
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.
# File lib/metanorma/cli.rb, line 29 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()
click to toggle source
# File lib/metanorma/cli.rb, line 49 def self.templates_path home_directory.join("templates") end
writable_templates_path?()
click to toggle source
# File lib/metanorma/cli.rb, line 71 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 directory" end return true end