Skip to content

Commit cbca1a6

Browse files
committed
Better message if the user tries to run the interactive commands in non-interactive mode
1 parent 4d09842 commit cbca1a6

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

app/core/base_tool2.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ def parse_options
8787

8888
def ask(question)
8989
print "#{question}: "
90-
STDIN.gets.strip
90+
str = STDIN.gets
91+
92+
if str.nil?
93+
raise CannotReadStdinError, "Cannot read from stdin. This could mean that you're trying to run the tool in a "\
94+
"non-interactive mode. Please run the tool in an interactive mode or provide all the required options as command line arguments."
95+
end
96+
97+
str.strip
9198
end
9299

93100
def ask_yes_or_no(question, default)

app/core/patchkit_error.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ class APIJobError < APIError
2020
end
2121
class APIPublishError < StandardError
2222
end
23+
24+
class CannotReadStdinError < StandardError
25+
def initialize(message = 'Cannot read from stdin')
26+
super(message)
27+
end
28+
end
2329
end

app/make_version.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,21 @@ def execute
120120
validate_source_version! unless mode_files?
121121

122122
if !draft_version.nil?
123-
if draft_version.processing_finished_at
124-
if !@overwrite_draft && !ask_yes_or_no("A draft version already exists and contains processed content. "\
125-
"Are you sure you want to overwrite it?", "n")
126-
exit
127-
end
128-
else
129-
if !@overwrite_draft && !ask_yes_or_no("A draft version already exists, but no content was uploaded. "\
130-
"Are you sure you want to upload the content and overwrite its metadata?", "y")
131-
exit
123+
begin
124+
if draft_version.processing_finished_at
125+
if !@overwrite_draft && !ask_yes_or_no("A draft version already exists and contains processed content. "\
126+
"Are you sure you want to overwrite it?", "n")
127+
exit
128+
end
129+
else
130+
if !@overwrite_draft && !ask_yes_or_no("A draft version already exists, but no content was uploaded. "\
131+
"Are you sure you want to upload the content and overwrite its metadata?", "y")
132+
exit
133+
end
132134
end
135+
rescue CannotReadStdinError => e
136+
raise CannotReadStdinError, "Running in non-interactive mode and not allowed to overwrite draft version. "\
137+
"Please use --overwrite-draft option or run in interactive mode."
133138
end
134139
else
135140
create_draft_version!

0 commit comments

Comments
 (0)