Class: BaiduPcs::Cli::FsCli
- Defined in:
- lib/baidu_pcs/cli/fs_cli.rb
Instance Method Summary collapse
- #copy(from_rpath, to_rpath) ⇒ Object
- #delete(rpath) ⇒ Object
- #download(rpath) ⇒ Object
- #list(rpath = nil) ⇒ Object
- #meta(rpath) ⇒ Object
- #mkdir(rpath) ⇒ Object
- #move(from_rpath, to_rpath) ⇒ Object
- #search(keyword, rpath = nil) ⇒ Object
- #streamurl(rpath) ⇒ Object
- #upload(local_path, rpath = nil) ⇒ Object
Methods inherited from BaseCli
Instance Method Details
#copy(from_rpath, to_rpath) ⇒ Object
78 79 80 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 78 def copy(from_rpath, to_rpath) say BaiduPcs::Fs.copy(from_rpath, to_rpath).body end |
#delete(rpath) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 85 def delete(rpath) if [:force] || yes?("Are you sure to delte #{rpath}?") say BaiduPcs::Fs.delete(rpath).body else say "Cancel to delete #{rpath}" end end |
#download(rpath) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 25 def download(rpath) opts = .dup local_app_root = opts.delete(:tosync) ? BaiduPcs::Config.local_app_root : Dir.pwd local_path = "#{local_app_root}/#{rpath}" body = BaiduPcs::Fs.download(rpath, opts).body FileUtils.mkdir_p(File.dirname(local_path)) if File.exists?(local_path) extname = File.extname(local_path) = ".#{Time.now.strftime('%Y%m%d%H%M%S')}-#{rand(100)}#{extname}" if extname.blank? local_path += else local_path.gsub!(extname, ) end end File.binwrite(local_path, body) say local_path end |
#list(rpath = nil) ⇒ Object
65 66 67 68 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 65 def list(rpath=nil) res = BaiduPcs::Fs.list(rpath, .dup) res.body[:list].each{|item| print_item(item) } end |
#meta(rpath) ⇒ Object
56 57 58 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 56 def (rpath) say BaiduPcs::Fs.(rpath).body end |
#mkdir(rpath) ⇒ Object
51 52 53 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 51 def mkdir(rpath) say BaiduPcs::Fs.mkdir(rpath).body end |
#move(from_rpath, to_rpath) ⇒ Object
72 73 74 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 72 def move(from_rpath, to_rpath) say BaiduPcs::Fs.move(from_rpath, to_rpath).body end |
#search(keyword, rpath = nil) ⇒ Object
96 97 98 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 96 def search(keyword, rpath=nil) say BaiduPcs::Fs.search(keyword, rpath, ).body end |
#streamurl(rpath) ⇒ Object
45 46 47 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 45 def streamurl(rpath) say BaiduPcs::Fs.streamurl(rpath) end |
#upload(local_path, rpath = nil) ⇒ Object
18 19 20 21 |
# File 'lib/baidu_pcs/cli/fs_cli.rb', line 18 def upload(local_path, rpath=nil) res = BaiduPcs::Fs.upload(File.(local_path), rpath, .dup) print_item res.body end |