Class: EnfCli::Shell::CLI
Overview
Instance Method Summary
collapse
Methods inherited from EnfThor
capture_stdout, command_help, handle_argument_error, help
Instance Method Details
#cat(file) ⇒ Object
396
397
398
399
400
401
402
403
404
405
406
|
# File 'lib/enfcli.rb', line 396
def cat(file)
try_with_rescue do
file = EnfCli::expand_path(file)
raise EnfCli::ERROR, "#{file} not found!" unless File.exists?(file)
say File.readlines(file).join
end
end
|
#cd(dir = "~") ⇒ Object
418
419
420
421
422
423
424
425
|
# File 'lib/enfcli.rb', line 418
def cd(dir = "~")
try_with_rescue do
dir = EnfCli::expand_path(dir)
raise EnfCli::ERROR, "No such directory #{dir}" unless Dir.exist?(dir)
Dir.chdir(dir)
end
end
|
#clear ⇒ Object
437
438
439
440
441
442
|
# File 'lib/enfcli.rb', line 437
def clear
try_with_rescue do
clear_code = %x{clear}
print clear_code or system("cls")
end
end
|
#display_session_token ⇒ Object
446
447
448
449
450
|
# File 'lib/enfcli.rb', line 446
def display_session_token
try_with_rescue_in_session do
say EnfCli::CTX.instance.auth_token.to_s
end
end
|
#host ⇒ Object
429
430
431
432
433
|
# File 'lib/enfcli.rb', line 429
def host
try_with_rescue do
say EnfCli::CTX.instance.host, :bold
end
end
|
#ls(dir = nil) ⇒ Object
383
384
385
386
387
388
389
390
391
392
|
# File 'lib/enfcli.rb', line 383
def ls(dir = nil)
try_with_rescue do
dir ||= "."
dir = EnfCli::expand_path(dir)
Dir.entries(dir).each { |f|
puts f unless f.start_with?(".")
}
end
end
|
#pwd ⇒ Object
410
411
412
413
414
|
# File 'lib/enfcli.rb', line 410
def pwd
try_with_rescue do
say Dir.pwd
end
end
|
#refresh_session_token ⇒ Object
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
# File 'lib/enfcli.rb', line 454
def refresh_session_token
try_with_rescue_in_session do
host = EnfCli::CTX.instance.host
user = EnfCli::CTX.instance.user
say "Refreshing session token.....", :bold
password = EnfCli::ask_password()
resp = EnfApi::API.instance.authenticate(host, user, password)
EnfCli::CTX.instance.session = resp[:data][0]
say "Refreshed session token!", :green
end
end
|