Class: RecordOnChain::Commands::Secret

Inherits:
AbstractCommand show all
Includes:
M_GetSecret, M_LoadDatafile
Defined in:
lib/record_on_chain/commands/secret.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from M_GetSecret

#get_secret

Methods included from M_LoadDatafile

#load_datafile

Methods inherited from AbstractCommand

#squeeze_args_from_argv

Constructor Details

#initialize(argv = ARGV, cli = Cli.new) ⇒ Secret



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/record_on_chain/commands/secret.rb', line 26

def initialize( argv= ARGV , cli= Cli.new )
  super( argv.first , cli )
  val_context  = { "-k" => :keyfile_path }
  flag_context = {}

  args = squeeze_args_from_argv( val_context , flag_context , argv )

  default_path = Pathname.new( Dir.home ) +
                 MAINDIR_NAME   +
                 D_KEYFILE_NAME ;
  keyfile_path = args[:keyfile_path] ? args[:keyfile_path] : default_path.to_s

  @keyfile = load_datafile( keyfile_path , "keyfile" )
rescue => e
  roc_exit( :halt , "#{e.message}" )
end

Class Method Details

.descriptionObject



12
13
14
# File 'lib/record_on_chain/commands/secret.rb', line 12

def self.description
  return "recover secret from keyfile"
end

.usageObject



16
17
18
19
20
21
22
23
24
# File 'lib/record_on_chain/commands/secret.rb', line 16

def self.usage
  output = <<-EOS
 -k <value> => keyfile path ( default : $HOME/.ro_chain/default_key.yml )

 (e.g.) keyfile_path:/home/user/doc/.ro_chain/my_key.yml
 => $ rochain secret -k /home/user/doc/.ro_chain/my_key.yml
  EOS
  return output
end

Instance Method Details

#startObject



43
44
45
46
47
48
49
# File 'lib/record_on_chain/commands/secret.rb', line 43

def start
  secret = get_secret( @cli, @keyfile )
  msg    = "Secret [ #{secret} ]"
  roc_exit( :nomal_end , msg )
rescue => e
  roc_exit( :halt , "#{e.message}" )
end