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
404
405
406
407
408
409
410
411
412
413
414
|
# File 'lib/enfcli.rb', line 404
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
426
427
428
429
430
431
432
433
|
# File 'lib/enfcli.rb', line 426
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
445
446
447
448
449
450
|
# File 'lib/enfcli.rb', line 445
def clear
try_with_rescue do
clear_code = %x{clear}
print clear_code or system("cls")
end
end
|
#display_session_token ⇒ Object
454
455
456
457
458
|
# File 'lib/enfcli.rb', line 454
def display_session_token
try_with_rescue_in_session do
say EnfCli::CTX.instance.auth_token.to_s
end
end
|
#host ⇒ Object
437
438
439
440
441
|
# File 'lib/enfcli.rb', line 437
def host
try_with_rescue do
say EnfCli::CTX.instance.host, :bold
end
end
|
#ls(dir = nil) ⇒ Object
391
392
393
394
395
396
397
398
399
400
|
# File 'lib/enfcli.rb', line 391
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
418
419
420
421
422
|
# File 'lib/enfcli.rb', line 418
def pwd
try_with_rescue do
say Dir.pwd
end
end
|
#refresh_session_token ⇒ Object
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
# File 'lib/enfcli.rb', line 462
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
|