Module: Fargo::CLI::NickBrowser

Extended by:
ActiveSupport::Concern
Included in:
Console
Defined in:
lib/fargo/cli/nick_browser.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#begin_browsing(nick, above_prompt = true) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/fargo/cli/nick_browser.rb', line 95

def begin_browsing nick, above_prompt = true
  @cwd = Pathname.new '/'
  @file_list = client.file_list(@browsing)

  if above_prompt
    Readline.above_prompt{ puts "#{@browsing} ready for browsing" }
  else
    puts "#{@browsing} ready for browsing"
  end
end

#browse(nick) ⇒ Object



52
53
54
55
56
57
# File 'lib/fargo/cli/nick_browser.rb', line 52

def browse nick
  @browsing  = nick
  @file_list = nil
  list       = client.file_list nick
  begin_browsing nick, false if list.is_a?(Hash)
end

#cd(dir = '/') ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/fargo/cli/nick_browser.rb', line 59

def cd dir = '/'
  cwd = resolve(dir)
  if drilldown(cwd, @file_list).nil?
    puts "#{dir.inspect} doesn't exist!"
  else
    @cwd = cwd
    pwd
  end
end

#ls(dir = '') ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fargo/cli/nick_browser.rb', line 75

def ls dir = ''
  if @cwd.nil? || @file_list.nil?
    puts "Note browsing any nick!"
    return
  end

  hash = drilldown(resolve(dir), @file_list)

  hash.keys.sort_by(&:downcase).
      sort_by{ |k| hash[k].is_a?(Hash) ? 0 : 1 }.each do |key|
    if hash[key].is_a?(Hash)
      puts "#{key}/"
    else
      printf "%10s -- %s\n", humanize_bytes(hash[key].size), key
    end
  end

  true
end

#pwdObject Also known as: cwd



69
70
71
# File 'lib/fargo/cli/nick_browser.rb', line 69

def pwd
  puts @cwd.to_s
end