Parent

Class/Module Index [+]

Quicksearch

DavCLI

DavClient Command Line Utility

Public Class Methods

cat(args) click to toggle source
# File lib/davclient/davcli.rb, line 64
def self.cat(args)
  if(show_help?(args))
    puts "Usage: #{$0} cat [url|filename]"
    puts
    puts "Concatenate and print remote files to local terminal."
  end
  if(args.size == 1)
    url = args[0]
    puts WebDAV.get(url)
  else
    puts "Illegal arguments: " + args[1..100].join(" ")
    puts "Usage: #{$0} cat [url|filename]"
  end
end
cd(args) click to toggle source
# File lib/davclient/davcli.rb, line 101
def self.cd(args)
  if(show_help?(args))
    puts "Usage: #{$0} cd [url|remote-path]"
    puts
    puts "Change current working working url."
    puts
    puts "Examples: "
    puts "     #{$0} cd https://www.webdav.org/"
    puts "     #{$0} cd ../test"
    puts
    exit
  end
  url = args[0]
  if(url == nil)then
    puts "#{$0} cd: Missing mandatory url."
    exit
  end
  begin
    WebDAV.cd(url)
    puts "Changing WebDAV URL to: " + WebDAV.CWURL
  rescue Exception => exception
    puts exception
  end
end
cp(args) click to toggle source
# File lib/davclient/davcli.rb, line 179
def self.cp(args)
  if(args.size == 2 )
    WebDAV.cp(args[0], args[1])
  else
    puts "Usage '#{$0} cp src dest"
    puts
    puts "Copy resources on remote server."
  end
end
dav(args) click to toggle source
# File lib/davclient/davcli.rb, line 223
def self.dav(args)

  $0 = $0.sub(/.*\//,"").sub(/.rb$/,"")

  command =  args[0]

  if(args.size == 0 or command == "-h" or command =~ /help/ or command =~ /\?/) then
    print_dav_usage
  end

  if(command == "-v" or command =~ /version/ ) then
    puts "#{$0} version " + WebDAV.version
    exit
  end

  args = args[1..100]
  case command
    when "put" then
      PutCLI.put(args)
    when "get" then
      get(args)
    when "edit" then
      edit(args)
    when "cat" then
      cat(args)
    when "ls" then
      LsCLI.ls(args)
    when "pwd"
      pwd(args)
    when "cd"
      cd(args)
    when "cp"
      cp(args)
    when "copy"
      cp(args)
    when "mv"
      mv(args)
    when "move"
      mv(args)
    when "mkcol"
       mkcol(args)
    when "mkdir"
       mkcol(args)
    when "put"
       PutCLI.put(args)
    when "delete"
      delete(args)
    when "del"
      delete(args)
    when "rm"
      delete(args)
    when "propfind"
      propfind(args)
    when "props"
      propfind(args)
    when "options"
      options(args)
    else
      puts "Unknown command :'" + command + "'"
      print_dav_usage
    end
end
delete(args) click to toggle source
# File lib/davclient/davcli.rb, line 151
def self.delete(args)
  if(show_help?(args) or args.size != 1)
    puts "Usage: #{$0} delete [url|path]"
    puts
    puts "Delete remote collection (folder) or file."
  else
    url = WebDAV.delete(args[0])
  end
end
edit(args) click to toggle source
# File lib/davclient/davcli.rb, line 17
def self.edit(args)
  if(show_help?(args))
    print_edit_usage
  else
    if(args.size == 1)
      url = args[0]
      content = WebDAV.get(url)
      tmp_filename = WebDAV.tmp_folder + File.basename(url)
      File.open(tmp_filename, 'w') {|f| f.write(content) }
      system("emacs --quick -nw " + tmp_filename)
      new_content = nil
      File.open(tmp_filename, 'r') {|f| new_content = f.read() }
      WebDAV.put_string(url, new_content)
    else
      puts "Illegal arguments: " + args[1..100].join(" ")
      print_edit_usage
    end
  end
end
get(args) click to toggle source

TODO

- Handle glob (ie *.gif) => Tell user to quote to avoid shell glob: dav get "*.html"
# File lib/davclient/davcli.rb, line 39
def self.get(args)

  puts "DEBUG:"
  if(args.size == 1 or args.size == 2 )
    url = args[0]
    content =  WebDAV.get(url)
    filename = ""
    if(args.size == 1)
      filename = File.basename(url)
    else
      # Handle relative paths in local filenames or local dir
      path = Pathname.new(Pathname.pwd)
      path = path + args[1]
      filename = path.to_s
      if(args[1] =~ /\/$/ or args[1] =~ /\.$/)
        path = path + filename = filename + "/" + File.basename(url)
      end
    end
    File.open(filename, 'w') {|f| f.write(content) }
  else
    puts "Illegal arguments: " + args[1..100].join(" ")
    puts "#{$0}: usage '#{$0} get remote-url [local]"
  end
end
ls(args) click to toggle source
# File lib/davclient/davcli.rb, line 175
def self.ls(args)
  LsCLI.ls(args)
end
mkcol(args) click to toggle source
# File lib/davclient/davcli.rb, line 126
def self.mkcol(args)
  if(show_help?(args))
    puts "Usage: #{$0} mkcol [url|remote-path]"
    puts
    puts "Create collection (folder) on remote server."
    puts "The command 'mkdir' is an alias for 'mkcol'."
    puts
    puts "Examples: "
    puts "     #{$0} mkcol new_collection"
    puts "     #{$0} mkcol https://www.webdav.org/new_collection/"
    puts "     #{$0} mkcol ../new_collection"
    puts
    exit
  end
  if(args.size == 1 )
    if( args[0] =~ /^http/ || WebDAV.CWURL )
      WebDAV.mkcol(args[0])
    else
      puts "Error: #{$0} mkcol: No working url set. Use '#{$0} cd url' to set url."
    end
  else
    puts "#{$0}: usage '#{$0} mkcol [url|path]"
  end
end
mv(args) click to toggle source
# File lib/davclient/davcli.rb, line 190
def self.mv(args)
  if(args.size == 2 )
    WebDAV.mv(args[0], args[1])
  else
    puts "Usage '#{$0} copy mv dest"
    puts
    puts "Move resources on remote server."
  end
end
options(args) click to toggle source
# File lib/davclient/davcli.rb, line 161
def self.options(args)
  if((args.size == 0 or args.size == 1) and !show_help?(args))
    puts WebDAV.options(args[0])
  else
    puts "Usage: #{$0} options [url]"
    puts
    puts "Prints remote server options and http headers. "
  end
end
propfind(args) click to toggle source
# File lib/davclient/davcli.rb, line 171
def self.propfind(args)
  PropfindCLI.propfind(args)
end
pwd(args) click to toggle source
# File lib/davclient/davcli.rb, line 85
def self.pwd(args)
  if(show_help?(args))
    puts "Usage: #{$0} pwd"
    puts ""
    puts "Print current working url."
    exit
  end
  cwurl = WebDAV.CWURL
  if(cwurl)
    puts cwurl
  else
    puts "#{$0}: No working url set. Use 'dav cd url' to set url"
  end

end
show_help?(args) click to toggle source
# File lib/davclient/davcli.rb, line 79
def self.show_help?(args)
  return (args.grep("-?").size > 0 or
          args.grep("-h").size > 0 or
          args.grep("--help").size > 0 )
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.