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



237
238
239
# File 'lib/osdn/cli.rb', line 237

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

Instance Method Details

#helpObject



232
233
234
235
# File 'lib/osdn/cli.rb', line 232

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

#runObject



201
202
203
204
# File 'lib/osdn/cli.rb', line 201

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

#setObject



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/osdn/cli.rb', line 215

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



206
207
208
209
210
211
212
213
# File 'lib/osdn/cli.rb', line 206

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