lib/vectory/cli.rb in vectory-0.7.0 vs lib/vectory/cli.rb in vectory-0.7.1
- old
+ new
@@ -9,10 +9,11 @@
STATUS_UNSUPPORTED_INPUT_FORMAT_ERROR = 2
STATUS_UNSUPPORTED_OUTPUT_FORMAT_ERROR = 3
STATUS_CONVERSION_ERROR = 4
STATUS_SYSTEM_CALL_ERROR = 5
STATUS_INKSCAPE_NOT_FOUND_ERROR = 6
+ STATUS_SAME_FORMAT_ERROR = 7
MAP_ERROR_TO_STATUS = {
Vectory::ConversionError => STATUS_CONVERSION_ERROR,
Vectory::InkscapeNotFoundError => STATUS_INKSCAPE_NOT_FOUND_ERROR,
Vectory::SystemCallError => STATUS_SYSTEM_CALL_ERROR,
@@ -60,10 +61,14 @@
unless supported_format?(options[:format])
return unsupported_format_error(options[:format])
end
input_format = detect_input_format(file)
+ if same_format?(input_format, options[:format])
+ return same_format_error(options[:format])
+ end
+
unless supported_input_format?(input_format)
return unsupported_input_format_error
end
object = source_object(file, input_format)
@@ -89,9 +94,19 @@
STATUS_UNSUPPORTED_OUTPUT_FORMAT_ERROR
end
def detect_input_format(file)
FileMagic.detect(file)
+ end
+
+ def same_format?(input_format, output_format)
+ input_format.to_s == output_format
+ end
+
+ def same_format_error(format)
+ Vectory.ui.error("Could not convert to the same format '#{format}'.")
+
+ STATUS_SAME_FORMAT_ERROR
end
def supported_input_format?(format)
SupportedInputFormats.all.include?(format)
end