Class: EnfCli::Shell::CLI

Inherits:
EnfThor
  • Object
show all
Defined in:
lib/enfcli.rb

Overview

Shell CLI class

Instance Method Summary collapse

Methods inherited from EnfThor

capture_stdout, help

Instance Method Details

#cat(file) ⇒ Object



335
336
337
338
339
340
341
342
343
344
345
# File 'lib/enfcli.rb', line 335

def cat(file)
  try_with_rescue do
    # expand path
    file = EnfCli::expand_path(file)
    
    ## return if keyfile not found
    raise EnfCli::ERROR, "#{file} not found!" unless File.exists?(file)

    say File.readlines(file).join
  end
end

#cd(dir = "~") ⇒ Object



355
356
357
358
359
360
361
# File 'lib/enfcli.rb', line 355

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

#clearObject



371
372
373
374
375
376
# File 'lib/enfcli.rb', line 371

def clear
  try_with_rescue do
    clear_code = %x{clear}
    print clear_code or system("cls")
  end
end

#hostObject



364
365
366
367
368
# File 'lib/enfcli.rb', line 364

def host
  try_with_rescue do
    say EnfCli::CTX.instance.host, :bold
  end
end

#ls(dir = nil) ⇒ Object



323
324
325
326
327
328
329
330
331
332
# File 'lib/enfcli.rb', line 323

def ls(dir = nil)
  try_with_rescue do
    dir = "." unless dir
    dir = EnfCli::expand_path( dir )
    
    Dir.entries( dir ).each{ |f|
      puts f unless f.start_with?('.')
    }
  end
end

#pwdObject



348
349
350
351
352
# File 'lib/enfcli.rb', line 348

def pwd
  try_with_rescue do
    say Dir.pwd
  end
end