Class: SecretKeys::CLI::Init
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#format, #initialize, #parse_additional_options, #secrets
Constructor Details
This class inherits a constructor from SecretKeys::CLI::Base
Instance Method Details
#action_name ⇒ Object
162 163 164 |
# File 'lib/secret_keys/cli.rb', line 162 def action_name "init" end |
#run! ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/secret_keys/cli.rb', line 166 def run! @secrets = SecretKeys.new({}, secret_key) if input.is_a?(String) contents = encrypted_file_contents begin # Open with exclusive create so a file created by another process # between now and the write can never be clobbered. The file is # created readable and writable only by the owner. File.open(input, File::WRONLY | File::CREAT | File::EXCL, 0o600) do |file| file.write(contents) end rescue Errno::EEXIST warn "Error: Cannot init preexisting file '#{input}'" warn "You may want to try calling `secret_keys encrypt/edit` instead" exit 1 end else $stdout.write(encrypted_file_contents) end end |