Class: TreeRepl::Ls
Instance Attribute Summary
Attributes inherited from Cmd
Instance Method Summary collapse
- #exec(args) ⇒ Object
- #help ⇒ Object
-
#initialize(repl) ⇒ Ls
constructor
A new instance of Ls.
- #ls_print(n, prefix = nil) ⇒ Object
- #pr(s, prefix) ⇒ Object
Constructor Details
#initialize(repl) ⇒ Ls
Returns a new instance of Ls.
18 19 20 |
# File 'lib/treerepl/cmds.rb', line 18 def initialize(repl) super(repl,'ls') end |
Instance Method Details
#exec(args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/treerepl/cmds.rb', line 21 def exec(args) def ls_print(n,prefix=nil) def pr(s,prefix) if prefix puts File.join prefix,s else puts s end end puts if prefix ['.','..'].each do |s| pr s,prefix end n.children.each do |node| pr node.name,prefix end end args = ['.'] if args.empty? args.uniq! args.each do |path| n = repl.eval_path repl.cur,path if n prefix = args.length > 1 ? path : nil ls_print n,prefix end end end |
#help ⇒ Object
48 49 50 |
# File 'lib/treerepl/cmds.rb', line 48 def help 'List directory' end |
#ls_print(n, prefix = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/treerepl/cmds.rb', line 22 def ls_print(n,prefix=nil) def pr(s,prefix) if prefix puts File.join prefix,s else puts s end end puts if prefix ['.','..'].each do |s| pr s,prefix end n.children.each do |node| pr node.name,prefix end end |
#pr(s, prefix) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/treerepl/cmds.rb', line 23 def pr(s,prefix) if prefix puts File.join prefix,s else puts s end end |