File tree Expand file tree Collapse file tree 3 files changed +28
-10
lines changed
Expand file tree Collapse file tree 3 files changed +28
-10
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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
2329end
Original file line number Diff line number Diff 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!
You can’t perform that action at this time.
0 commit comments