Class: LocalVault::CLI::IdentityCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/localvault/cli/identity_cmd.rb

Constant Summary collapse

ALIAS_PATTERN =
/\A[a-zA-Z0-9][a-zA-Z0-9_-]{0,31}\z/

Instance Method Summary collapse

Instance Method Details

#set(field, value) ⇒ Object

Set an identity field. Only alias is supported today.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/localvault/cli/identity_cmd.rb', line 29

def set(field, value)
  unless field == "alias"
    $stderr.puts "Error: Unknown field '#{field}'. Supported: alias"
    exit 1
  end
  unless value.match?(ALIAS_PATTERN)
    $stderr.puts "Error: Alias must be 1-32 characters: letters, digits, '-' or '_', starting with a letter or digit."
    exit 1
  end
  Config.identity_alias = value
  $stdout.puts "Alias set to '#{value}'."
end

#showObject

Print the local identity summary: the configured alias, the InventList handle (if logged in), and the sync public key (if any).



11
12
13
14
15
# File 'lib/localvault/cli/identity_cmd.rb', line 11

def show
  $stdout.puts "Alias:      #{Config.identity_alias || "-"}"
  $stdout.puts "Handle:     #{Config.inventlist_handle ? "@#{Config.inventlist_handle}" : "-"}"
  $stdout.puts "Public key: #{Identity.exists? ? Identity.public_key : "- (run: localvault keygen)"}"
end

#unset(field) ⇒ Object

Clear an identity field. Only alias is supported today.



44
45
46
47
48
49
50
51
52
# File 'lib/localvault/cli/identity_cmd.rb', line 44

def unset(field)
  unless field == "alias"
    $stderr.puts "Error: Unknown field '#{field}'. Supported: alias"
    exit 1
  end
  previous = Config.identity_alias
  Config.identity_alias = nil
  $stdout.puts(previous ? "Alias '#{previous}' cleared." : "No alias set.")
end