require "thread" require "vmc/cli/app/base" module VMC::App class Files < Base desc "Print out an app's file contents" group :apps, :info input :app, :desc => "Application to inspect the files of", :argument => true, :from_given => by_name(:app) input :path, :desc => "Path of file to read", :argument => :optional, :default => "/" def file app = input[:app] path = input[:path] file = with_progress("Getting file contents") do app.file(*path.split("/")) end if quiet? print file else line file.split("\n").each do |l| line l end end rescue CFoundry::NotFound fail "Invalid path #{b(path)} for app #{b(app.name)}" rescue CFoundry::FileError => e fail e.description end desc "Examine an app's files" group :apps, :info input :app, :desc => "Application to inspect the files of", :argument => true, :from_given => by_name(:app) input :path, :desc => "Path of directory to list", :argument => :optional, :default => "/" def files app = input[:app] path = input[:path] if quiet? files = with_progress("Getting file listing") do app.files(*path.split("/")) end files.each do |file| line file.join("/") end else invoke :file, :app => app, :path => path end rescue CFoundry::NotFound fail "Invalid path #{b(path)} for app #{b(app.name)}" rescue CFoundry::FileError => e fail e.description end end end