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
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/enfcli.rb', line 407
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
429
430
431
432
433
434
435
436
|
# File 'lib/enfcli.rb', line 429
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
448
449
450
451
452
453
|
# File 'lib/enfcli.rb', line 448
def clear
try_with_rescue do
clear_code = %x{clear}
print clear_code or system("cls")
end
end
|
#display_session_token ⇒ Object
457
458
459
460
461
|
# File 'lib/enfcli.rb', line 457
def display_session_token
try_with_rescue_in_session do
say EnfCli::CTX.instance.auth_token.to_s
end
end
|
#host ⇒ Object
440
441
442
443
444
|
# File 'lib/enfcli.rb', line 440
def host
try_with_rescue do
say EnfCli::CTX.instance.host, :bold
end
end
|
#ls(dir = nil) ⇒ Object
394
395
396
397
398
399
400
401
402
403
|
# File 'lib/enfcli.rb', line 394
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
421
422
423
424
425
|
# File 'lib/enfcli.rb', line 421
def pwd
try_with_rescue do
say Dir.pwd
end
end
|
#refresh_session_token ⇒ Object
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
# File 'lib/enfcli.rb', line 465
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
|