Class: OSDN::CLI::Command::Vars

Inherits:
Base
  • Object
show all
Defined in:
lib/osdn/cli.rb

Instance Attribute Summary

Attributes inherited from Base

#credential, #format, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#credential_path, #initialize, #load_credential, #load_variables, #set_client_token, #set_credential, #update_token, #update_variables, #write_credential, #write_variables

Constructor Details

This class inherits a constructor from OSDN::CLI::Command::Base

Class Method Details

.descriptionObject



257
258
259
# File 'lib/osdn/cli.rb', line 257

def self.description
  "Get/set request environment variable."
end

Instance Method Details

#helpObject



252
253
254
255
# File 'lib/osdn/cli.rb', line 252

def help
  puts "#{$0} vars show [name]            -- Show current variable"
  puts "#{$0} vars set <name> <value>     -- Save variable to .osdn.vars"
end

#runObject



221
222
223
224
# File 'lib/osdn/cli.rb', line 221

def run
  subcommand = ARGV.shift ||'show'
  self.send subcommand
end

#setObject



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/osdn/cli.rb', line 235

def set
  name, value = ARGV.shift, ARGV.shift
  if !name || name.empty?
    logger.fatal "Missing variable name"
    help
    exit
  end
  if !value || value.empty?
    logger.fatal "Missing variable value"
    help
    exit
  end
  vars = load_variables('.', false)
  vars[name] = value
  write_variables vars
end

#showObject



226
227
228
229
230
231
232
233
# File 'lib/osdn/cli.rb', line 226

def show
  name = ARGV.shift
  if name
    puts load_variables[name]
  else
    pp load_variables
  end
end