diff --git a/bin/evaluate-all b/bin/evaluate-all index ec7ea92..0955f3e 100755 --- a/bin/evaluate-all +++ b/bin/evaluate-all @@ -2,7 +2,7 @@ set -e -ARGS="--directory ~/Code/link" +ARGS="--directory ~/Code/link --force" bin/mosaik evaluate ${ARGS} --input tmp/structural_logical_contributor.csv --output tmp/evaluation/structural_logical_contributor.csv --statistics tmp/evaluation/structural_logical_contributor.yml bin/mosaik evaluate ${ARGS} --input tmp/structural_logical.csv --output tmp/evaluation/structural_logical.csv --statistics tmp/evaluation/structural_logical.yml diff --git a/bin/extract-all b/bin/extract-all index 8716eab..55712f6 100755 --- a/bin/extract-all +++ b/bin/extract-all @@ -2,6 +2,6 @@ set -e -ARGS="--directory ~/Code/link --output tmp/link.csv" +ARGS="--directory ~/Code/link --output tmp/link.csv --force" bin/mosaik extract ${ARGS} --since 2023-10-27 --limit 0 --reduce --visualize --renderer neato diff --git a/bin/identify-all b/bin/identify-all index 6ca5076..91bf641 100755 --- a/bin/identify-all +++ b/bin/identify-all @@ -2,7 +2,7 @@ set -e -ARGS="--directory ~/Code/link --input tmp/link.csv --debug" +ARGS="--directory ~/Code/link --input tmp/link.csv --debug --force" bin/mosaik identify ${ARGS} --structural 1 --logical 1 --contributor 1 --output tmp/structural_logical_contributor.csv bin/mosaik identify ${ARGS} --structural 1 --logical 1 --contributor 0 --output tmp/structural_logical.csv diff --git a/lib/mosaik/command.rb b/lib/mosaik/command.rb index dab44f2..e7c6227 100644 --- a/lib/mosaik/command.rb +++ b/lib/mosaik/command.rb @@ -13,9 +13,11 @@ def call; end ## # Base class for commands that output graphs + # class Graph < Command defaults input: "mosaik.csv", output: "mosaik.csv", + force: false, visualize: false, format: "svg", renderer: "dot", @@ -25,6 +27,7 @@ class Graph < Command argument "--input FILE", "Input file for the dependency graph (default: #{defaults[:input]})" argument "--output FILE", "Output file for the dependency graph (default: #{defaults[:output]})" + argument "--force", "Overwrite the output file if it exists (default: #{defaults[:force]})" argument "--visualize", "Enable graph visualization (default: #{defaults[:visualize]})" argument "--format FORMAT", "Graph visualization format: svg or png (default: #{defaults[:format]})" @@ -38,6 +41,7 @@ class Graph < Command def validate raise OptionError, "unknown format: #{options[:format]}" unless options[:format].in? ["svg", "png"] raise OptionError, "unknown renderer: #{options[:renderer]}" unless options[:renderer].in? ["dot", "fdp", "sfdp", "neato"] + raise OptionError, "output file exists: #{options[:output]}" if File.exist?(options[:output]) end protected diff --git a/spec/mosaik/command_spec.rb b/spec/mosaik/command_spec.rb index 85e553d..f51f725 100644 --- a/spec/mosaik/command_spec.rb +++ b/spec/mosaik/command_spec.rb @@ -5,10 +5,18 @@ describe MOSAIK::Command::Graph do subject(:command) { described_class.new(options, *arguments) } - let(:options) { { input: "README.md" } } + let(:options) { { input: "README.md", output: "doesnotexist.csv" } } let(:arguments) { [] } describe "#validate" do + describe "--output" do + let(:arguments) { ["--output", "README.md"] } + + it "raises an error" do + expect { command.validate }.to raise_error MOSAIK::OptionError, "output file exists: README.md" + end + end + describe "--visualize" do let(:arguments) { ["--visualize"] } diff --git a/spec/mosaik/commands/evaluate_spec.rb b/spec/mosaik/commands/evaluate_spec.rb index 9fb61de..38ec137 100644 --- a/spec/mosaik/commands/evaluate_spec.rb +++ b/spec/mosaik/commands/evaluate_spec.rb @@ -3,7 +3,7 @@ RSpec.describe MOSAIK::Commands::Evaluate do subject(:command) { build(:evaluate_command, options:, arguments:) } - let(:options) { { input: "README.md" } } + let(:options) { { input: "README.md", output: "doesnotexist.csv" } } let(:arguments) { [] } describe "#validate" do diff --git a/spec/mosaik/commands/extract_spec.rb b/spec/mosaik/commands/extract_spec.rb index 05c7118..939bfee 100644 --- a/spec/mosaik/commands/extract_spec.rb +++ b/spec/mosaik/commands/extract_spec.rb @@ -3,7 +3,7 @@ RSpec.describe MOSAIK::Commands::Extract do subject(:command) { build(:extract_command, options:, arguments:) } - let(:options) { { input: "README.md" } } + let(:options) { { input: "README.md", output: "doesnotexist.csv" } } let(:arguments) { [] } describe "#validate" do diff --git a/spec/mosaik/commands/identify_spec.rb b/spec/mosaik/commands/identify_spec.rb index f579f20..91f18f0 100644 --- a/spec/mosaik/commands/identify_spec.rb +++ b/spec/mosaik/commands/identify_spec.rb @@ -3,7 +3,7 @@ RSpec.describe MOSAIK::Commands::Identify do subject(:command) { build(:identify_command, options:, arguments:) } - let(:options) { { input: "README.md" } } + let(:options) { { input: "README.md", output: "doesnotexist.csv" } } let(:arguments) { [] } describe "#validate" do