Skip to content

Commit

Permalink
Merge pull request #325 from metanorma/feature/remove-no-prefix-in-pr…
Browse files Browse the repository at this point in the history
…ogress-and-install-fonts-322

feat: remove 'no' prefix in --no-progress and --no-install-fonts CLI flags #322
  • Loading branch information
opoudjis committed May 28, 2024
2 parents ebbb11c + 5797b26 commit e537533
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
12 changes: 8 additions & 4 deletions lib/metanorma/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
module Metanorma
module Cli
class Command < ThorWithConfig
class_option :no_progress, aliases: "-s", type: :boolean, default: true,
desc: "Don't show progress for long running tasks (like download)"
class_option :progress, aliases: "-s", type: :boolean, default: false,
desc: "Show progress for long running tasks (like download)"

desc "new NAME", "Create new Metanorma document"
option :type, aliases: "-t", required: true, desc: "Document type"
Expand All @@ -39,7 +39,7 @@ def new(name)
option :strict, aliases: "-S", type: :boolean, desc: "Strict compilation: abort if there are any errors"
option :agree_to_terms, type: :boolean, desc: "Agree / Disagree with all third-party licensing terms "\
"presented (WARNING: do know what you are agreeing with!)"
option :no_install_fonts, type: :boolean, desc: "Skip the font installation process"
option :install_fonts, type: :boolean, default: true, desc: "Install required fonts"
option :continue_without_fonts, type: :boolean, desc: "Continue processing even when fonts are missing"

def compile(file_name = nil)
Expand All @@ -64,7 +64,7 @@ def compile(file_name = nil)
option :coverpage, aliases: "-c", desc: "Liquid template"
option :agree_to_terms, type: :boolean, desc: "Agree / Disagree with all third-party licensing terms "\
"presented (WARNING: do know what you are agreeing with!)"
option :no_install_fonts, type: :boolean, desc: "Skip the font installation process"
option :install_fonts, type: :boolean, default: true, desc: "Install required fonts"
option :continue_without_fonts, type: :boolean, desc: "Continue processing even when fonts are missing"
option :strict, aliases: "-S", type: :boolean, \
desc: "Strict compilation: abort if there are any errors"
Expand Down Expand Up @@ -149,6 +149,10 @@ def list_doctypes(type = nil)
desc "config", "Manage configuration file"
subcommand :config, Metanorma::Cli::Commands::Config

def self.exit_on_failure?
true
end

private

def single_type_extensions(type)
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/cli/commands/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Site < ThorWithConfig
)
option :agree_to_terms, type: :boolean, desc: "Agree / Disagree with all third-party licensing terms "\
"presented (WARNING: do know what you are agreeing with!)"
option :no_install_fonts, type: :boolean, desc: "Skip the font installation process"
option :install_fonts, type: :boolean, default: true, desc: "Install required fonts"
option :continue_without_fonts, type: :boolean, desc: "Continue processing even when fonts are missing"
option :stylesheet, alias: "-s", desc: "Stylesheet file path for rendering HTML page"
option :template_dir, alias: "-t", desc: "Liquid template directory to render site design"
Expand Down
4 changes: 2 additions & 2 deletions lib/metanorma/cli/thor_with_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def options
def filter_compile_options(options)
copts = %w[
agree_to_terms
no_install_fonts
install_fonts
continue_without_fonts
no_progress
progress
strict
]
options.select { |k, _| copts.include?(k) }.symbolize_all_keys
Expand Down
18 changes: 15 additions & 3 deletions spec/acceptance/compile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
registered_tags = Metanorma::Registry.instance.root_tags

expect(registered_tags[:ogc]).to eq("ogc-standard")
expect(Metanorma::Cli::Compiler,).to have_received(:compile).
with(sample_asciidoc_file, format: :asciidoc, type: "iso", no_progress: true)
expect(Metanorma::Cli::Compiler).to have_received(:compile)
.with(
sample_asciidoc_file,
format: :asciidoc,
type: "iso",
progress: false,
install_fonts: true,
)
end

it "supports wildcard document selection" do
Expand All @@ -23,7 +29,13 @@

expect(Metanorma::Cli::Compiler).to have_received(:compile).thrice
expect(Metanorma::Cli::Compiler).to have_received(:compile)
.with(sample_asciidoc_file, format: :asciidoc, type: "iso", no_progress: true)
.with(
sample_asciidoc_file,
format: :asciidoc,
type: "iso",
progress: false,
install_fonts: true,
)
end
end

Expand Down
21 changes: 16 additions & 5 deletions spec/acceptance/generate_site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@

expect(output).to include("Site has been generated at #{output_dir}")
expect(Metanorma::Cli::SiteGenerator).to have_received(:generate).with(
source_dir.to_s, { output_dir: output_dir,
no_progress: true }, no_progress: true
source_dir.to_s,
{
output_dir: output_dir,
progress: false,
install_fonts: true,
},
{
progress: false,
install_fonts: true,
},
)

expect(Metanorma::Cli::Compiler).to have_received(:compile)
Expand All @@ -47,13 +55,15 @@
source_dir.to_s,
{
output_dir: output_dir,
no_progress: true,
progress: false,
continue_without_fonts: true,
strict: true,
install_fonts: true,
},
continue_without_fonts: true,
no_progress: true,
progress: false,
strict: true,
install_fonts: true,
)

expect(Metanorma::Cli::Compiler).to have_received(:compile)
Expand Down Expand Up @@ -95,7 +105,8 @@
expect(Metanorma::Cli::SiteGenerator).to have_received(:generate).with(
source_dir.to_s,
hash_including(template_dir: template_dir, stylesheet: stylesheet_path),
no_progress: true,
progress: false,
install_fonts: true,
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/metanorma/cli/commands/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@
it "config values have bigger priority then args" do
config_cli = Metanorma::Cli::Commands::Config.new
config_cli.set("cli.agree_to_terms", "true")
config_cli.set("cli.no_install_fonts", "true")
config_cli.set("cli.install_fonts", "true")
config_cli.set("cli.continue_without_fonts", "true")

result = Metanorma::Cli::Commands::Config.load_configs(
{ agree_to_terms: false,
no_install_fonts: false,
install_fonts: true,
continue_without_fonts: false },
[@test_config]
)

expect(result[:agree_to_terms]).to be true
expect(result[:no_install_fonts]).to be true
expect(result[:install_fonts]).to be true
expect(result[:continue_without_fonts]).to be true
end
end
4 changes: 2 additions & 2 deletions spec/metanorma/cli/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def attributes
type: "iso",
extract_type: [],
extension_keys: [],
no_install_fonts: true,
no_progress: true,
install_fonts: false,
progress: false,
}
end

Expand Down
4 changes: 2 additions & 2 deletions spec/metanorma/cli/site_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
source_path,
{ output_dir: output_directory },
continue_without_fonts: false,
no_progress: false,
progress: false,
)

expect(Metanorma::Cli::Compiler).to have_received(:compile).with(
Expand All @@ -46,7 +46,7 @@
format: :asciidoc,
output_dir: asset_directory,
continue_without_fonts: false,
no_progress: false,
progress: false,
site_generate: true,
)

Expand Down

0 comments on commit e537533

Please sign in to comment.