Module: EasyCreds::Actions::EditorEdit

Defined in:
lib/easy_creds/actions/editor_edit.rb

Class Method Summary collapse

Class Method Details

.call(ctx, local: false) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/easy_creds/actions/editor_edit.rb', line 10

def self.call(ctx, local: false)
  label = local ? "#{ctx.env}_local" : ctx.env
  Theme.section("Editor — credentials/#{label}.yml.enc")

  unless ctx.io.key_exists?(ctx.env, local: local)
    Theme.failure('No local key. Run `init` or `pull` first.')
    return
  end

  editor_cmd = resolve_editor
  unless editor_cmd
    Theme.failure("$VISUAL / $EDITOR is not set.\n  Examples: export EDITOR=\"code --wait\"")
    return
  end

  yaml_str = ctx.io.read_raw(ctx.env, local: local)
  saved    = edit_in_editor(ctx, label, yaml_str, editor_cmd, local: local)
  Actions::Push.call(ctx) if !local && saved && ctx.prompt.yes?('Push changes to 1Password now?')
end