Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/internal_events/cli/helpers/files.rb')
-rwxr-xr-xscripts/internal_events/cli/helpers/files.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/internal_events/cli/helpers/files.rb b/scripts/internal_events/cli/helpers/files.rb
new file mode 100755
index 00000000000..b613350353f
--- /dev/null
+++ b/scripts/internal_events/cli/helpers/files.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+# Helpers related reading/writing definition files
+module InternalEventsCli
+ module Helpers
+ module Files
+ def prompt_to_save_file(filepath, content)
+ cli.say <<~TEXT.chomp
+ #{format_info('Preparing to generate definition with these attributes:')}
+ #{filepath}
+ #{content}
+ TEXT
+
+ if File.exist?(filepath)
+ cli.error("Oh no! This file already exists!\n")
+
+ return if cli.no?(format_prompt('Overwrite file?'))
+
+ write_to_file(filepath, content, 'update')
+ elsif cli.yes?(format_prompt('Create file?'))
+ write_to_file(filepath, content, 'create')
+ end
+ end
+
+ def file_saved_message(verb, filepath)
+ " #{format_selection(verb)} #{filepath}"
+ end
+
+ def write_to_file(filepath, content, verb)
+ File.write(filepath, content)
+
+ file_saved_message(verb, filepath).tap { |message| cli.say "\n#{message}\n" }
+ end
+ end
+ end
+end