Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Raise when output file exists and add --force argument
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Apr 28, 2024
1 parent c7f06e1 commit 11206bd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bin/evaluate-all
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/extract-all
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion bin/identify-all
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/mosaik/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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]})"
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/mosaik/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
2 changes: 1 addition & 1 deletion spec/mosaik/commands/evaluate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/mosaik/commands/extract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/mosaik/commands/identify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11206bd

Please sign in to comment.