Class: RecordOnChain::Commands::Init

Inherits:
AbstractCommand show all
Defined in:
lib/record_on_chain/commands/init.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

#squeeze_args_from_argv

Constructor Details

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

Returns a new instance of Init.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/record_on_chain/commands/init.rb', line 33

def initialize( argv= ARGV , cli= Cli.new )
  super( argv.first , cli )
  val_context  = { "-p" => :path,
                   "-s" => :secret,
                   "-k" => :keyfile_name,
                   "-c" => :configfile_name }
  flag_context = { "-t" => :testnet }

  args = squeeze_args_from_argv( val_context , flag_context , argv )

  @secret          = args[:secret]
  @network_type    = args[:testnet] ? "testnet" : "mainnet"
  @maindir_path    = get_maindir_path( args[:path] ) # Pathname obj
  @keyfile_path    = get_datafile_path( "keyfile"    , args[:keyfile_name]    ) # Pathname obj
  @configfile_path = get_datafile_path( "configfile" , args[:configfile_name] ) # Pathname obj
rescue => e
  roc_exit( :halt , "#{e.message}" )
end

Class Method Details

.descriptionObject



15
16
17
# File 'lib/record_on_chain/commands/init.rb', line 15

def self.description
  return "initialize RecordOnChain"
end

.usageObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/record_on_chain/commands/init.rb', line 19

def self.usage
  output = <<-EOS
 -p <value> => base path         ( default : $HOME              )
 -s <value> => 32byte hex secret ( default : random hex         )
 -k <value> => keyfile name      ( default : default_key.yml    )
 -c <value> => configfile name   ( defailt : default_config.yml )
 -t         => network type      ( defailt : false -> mainnet   )

 (e.g.) secret:XXX , keyfile_name:mykey.yml , network_type:testnet
 => $ rochain init -k mykey.yml -s XXX -t
  EOS
  return output
end

Instance Method Details

#startObject

you can specify maindir path with argument.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/record_on_chain/commands/init.rb', line 53

def start
  @cli.puts_enhance_msg( "[ Start gnerate keyfile ]" )
  generate_keyfile

  @cli.puts_enhance_msg( "[ Start gnerate configfile ]" )
  generate_config

  @cli.blank_line

  # nomal_end
  roc_exit( :nomal_end )
rescue => e
  roc_exit( :halt , "#{e.message}" )
end