Class DavCLI
In: lib/davclient/davcli.rb
lib/davclient/davcli.rb
Parent: Object

DavClient Command Line Utility

Methods

cat   cat   cd   cd   cp   cp   dav   dav   delete   delete   edit   edit   get   get   ls   ls   mkcol   mkcol   mv   mv   options   options   print_dav_usage   print_dav_usage   print_edit_usage   print_edit_usage   propfind   propfind   pwd   pwd   show_help?   show_help?  

Public Class methods

[Source]

    # File lib/davclient/davcli.rb, line 64
64:   def self.cat(args)
65:     if(show_help?(args))
66:       puts "Usage: #{$0} cat [url|filename]"
67:       puts
68:       puts "Concatenate and print remote files to local terminal."
69:     end
70:     if(args.size == 1)
71:       url = args[0]
72:       puts WebDAV.get(url)
73:     else
74:       puts "Illegal arguments: " + args[1..100].join(" ")
75:       puts "Usage: #{$0} cat [url|filename]"
76:     end
77:   end

[Source]

    # File lib/davclient/davcli.rb, line 64
64:   def self.cat(args)
65:     if(show_help?(args))
66:       puts "Usage: #{$0} cat [url|filename]"
67:       puts
68:       puts "Concatenate and print remote files to local terminal."
69:     end
70:     if(args.size == 1)
71:       url = args[0]
72:       puts WebDAV.get(url)
73:     else
74:       puts "Illegal arguments: " + args[1..100].join(" ")
75:       puts "Usage: #{$0} cat [url|filename]"
76:     end
77:   end

[Source]

     # File lib/davclient/davcli.rb, line 101
101:   def self.cd(args)
102:     if(show_help?(args))
103:       puts "Usage: #{$0} cd [url|remote-path]"
104:       puts
105:       puts "Change current working working url."
106:       puts
107:       puts "Examples: "
108:       puts "     #{$0} cd https://www.webdav.org/"
109:       puts "     #{$0} cd ../test"
110:       puts
111:       exit
112:     end
113:     url = args[0]
114:     if(url == nil)then
115:       puts "#{$0} cd: Missing mandatory url."
116:       exit
117:     end
118:     begin
119:       WebDAV.cd(url)
120:       puts "Changing WebDAV URL to: " + WebDAV.CWURL
121:     rescue Exception => exception
122:       puts exception
123:     end
124:   end

[Source]

     # File lib/davclient/davcli.rb, line 101
101:   def self.cd(args)
102:     if(show_help?(args))
103:       puts "Usage: #{$0} cd [url|remote-path]"
104:       puts
105:       puts "Change current working working url."
106:       puts
107:       puts "Examples: "
108:       puts "     #{$0} cd https://www.webdav.org/"
109:       puts "     #{$0} cd ../test"
110:       puts
111:       exit
112:     end
113:     url = args[0]
114:     if(url == nil)then
115:       puts "#{$0} cd: Missing mandatory url."
116:       exit
117:     end
118:     begin
119:       WebDAV.cd(url)
120:       puts "Changing WebDAV URL to: " + WebDAV.CWURL
121:     rescue Exception => exception
122:       puts exception
123:     end
124:   end

[Source]

     # File lib/davclient/davcli.rb, line 179
179:   def self.cp(args)
180:     if(args.size == 2 )
181:       WebDAV.cp(args[0], args[1])
182:     else
183:       puts "Usage '#{$0} cp src dest"
184:       puts
185:       puts "Copy resources on remote server."
186:     end
187:   end

[Source]

     # File lib/davclient/davcli.rb, line 179
179:   def self.cp(args)
180:     if(args.size == 2 )
181:       WebDAV.cp(args[0], args[1])
182:     else
183:       puts "Usage '#{$0} cp src dest"
184:       puts
185:       puts "Copy resources on remote server."
186:     end
187:   end

[Source]

     # File lib/davclient/davcli.rb, line 223
223:   def self.dav(args)
224: 
225:     $0 = $0.sub(/.*\//,"").sub(/.rb$/,"")
226: 
227:     command =  args[0]
228: 
229:     if(args.size == 0 or command == "-h" or command =~ /help/ or command =~ /\?/) then
230:       print_dav_usage
231:     end
232: 
233:     if(command == "-v" or command =~ /version/ ) then
234:       puts "#{$0} version " + WebDAV.version
235:       exit
236:     end
237: 
238:     args = args[1..100]
239:     case command
240:       when "put" then
241:         PutCLI.put(args)
242:       when "get" then
243:         get(args)
244:       when "edit" then
245:         edit(args)
246:       when "cat" then
247:         cat(args)
248:       when "ls" then
249:         LsCLI.ls(args)
250:       when "pwd"
251:         pwd(args)
252:       when "cd"
253:         cd(args)
254:       when "cp"
255:         cp(args)
256:       when "copy"
257:         cp(args)
258:       when "mv"
259:         mv(args)
260:       when "move"
261:         mv(args)
262:       when "mkcol"
263:          mkcol(args)
264:       when "mkdir"
265:          mkcol(args)
266:       when "put"
267:          PutCLI.put(args)
268:       when "delete"
269:         delete(args)
270:       when "del"
271:         delete(args)
272:       when "rm"
273:         delete(args)
274:       when "propfind"
275:         propfind(args)
276:       when "props"
277:         propfind(args)
278:       when "options"
279:         options(args)
280:       else
281:         puts "Unknown command :'" + command + "'"
282:         print_dav_usage
283:       end
284:   end

[Source]

     # File lib/davclient/davcli.rb, line 223
223:   def self.dav(args)
224: 
225:     $0 = $0.sub(/.*\//,"").sub(/.rb$/,"")
226: 
227:     command =  args[0]
228: 
229:     if(args.size == 0 or command == "-h" or command =~ /help/ or command =~ /\?/) then
230:       print_dav_usage
231:     end
232: 
233:     if(command == "-v" or command =~ /version/ ) then
234:       puts "#{$0} version " + WebDAV.version
235:       exit
236:     end
237: 
238:     args = args[1..100]
239:     case command
240:       when "put" then
241:         PutCLI.put(args)
242:       when "get" then
243:         get(args)
244:       when "edit" then
245:         edit(args)
246:       when "cat" then
247:         cat(args)
248:       when "ls" then
249:         LsCLI.ls(args)
250:       when "pwd"
251:         pwd(args)
252:       when "cd"
253:         cd(args)
254:       when "cp"
255:         cp(args)
256:       when "copy"
257:         cp(args)
258:       when "mv"
259:         mv(args)
260:       when "move"
261:         mv(args)
262:       when "mkcol"
263:          mkcol(args)
264:       when "mkdir"
265:          mkcol(args)
266:       when "put"
267:          PutCLI.put(args)
268:       when "delete"
269:         delete(args)
270:       when "del"
271:         delete(args)
272:       when "rm"
273:         delete(args)
274:       when "propfind"
275:         propfind(args)
276:       when "props"
277:         propfind(args)
278:       when "options"
279:         options(args)
280:       else
281:         puts "Unknown command :'" + command + "'"
282:         print_dav_usage
283:       end
284:   end

[Source]

     # File lib/davclient/davcli.rb, line 151
151:   def self.delete(args)
152:     if(show_help?(args) or args.size != 1)
153:       puts "Usage: #{$0} delete [url|path]"
154:       puts
155:       puts "Delete remote collection (folder) or file."
156:     else
157:       url = WebDAV.delete(args[0])
158:     end
159:   end

[Source]

     # File lib/davclient/davcli.rb, line 151
151:   def self.delete(args)
152:     if(show_help?(args) or args.size != 1)
153:       puts "Usage: #{$0} delete [url|path]"
154:       puts
155:       puts "Delete remote collection (folder) or file."
156:     else
157:       url = WebDAV.delete(args[0])
158:     end
159:   end

[Source]

    # File lib/davclient/davcli.rb, line 17
17:   def self.edit(args)
18:     if(show_help?(args))
19:       print_edit_usage
20:     else
21:       if(args.size == 1)
22:         url = args[0]
23:         content = WebDAV.get(url)
24:         tmp_filename = WebDAV.tmp_folder + File.basename(url)
25:         File.open(tmp_filename, 'w') {|f| f.write(content) }
26:         system("emacs --quick -nw " + tmp_filename)
27:         new_content = nil
28:         File.open(tmp_filename, 'r') {|f| new_content = f.read() }
29:         WebDAV.put_string(url, new_content)
30:       else
31:         puts "Illegal arguments: " + args[1..100].join(" ")
32:         print_edit_usage
33:       end
34:     end
35:   end

[Source]

    # File lib/davclient/davcli.rb, line 17
17:   def self.edit(args)
18:     if(show_help?(args))
19:       print_edit_usage
20:     else
21:       if(args.size == 1)
22:         url = args[0]
23:         content = WebDAV.get(url)
24:         tmp_filename = WebDAV.tmp_folder + File.basename(url)
25:         File.open(tmp_filename, 'w') {|f| f.write(content) }
26:         system("emacs --quick -nw " + tmp_filename)
27:         new_content = nil
28:         File.open(tmp_filename, 'r') {|f| new_content = f.read() }
29:         WebDAV.put_string(url, new_content)
30:       else
31:         puts "Illegal arguments: " + args[1..100].join(" ")
32:         print_edit_usage
33:       end
34:     end
35:   end

TODO

 - Handle glob (ie *.gif) => Tell user to quote to avoid shell glob: dav get "*.html"

[Source]

    # File lib/davclient/davcli.rb, line 39
39:   def self.get(args)
40: 
41:     puts "DEBUG:"
42:     if(args.size == 1 or args.size == 2 )
43:       url = args[0]
44:       content =  WebDAV.get(url)
45:       filename = ""
46:       if(args.size == 1)
47:         filename = File.basename(url)
48:       else
49:         # Handle relative paths in local filenames or local dir
50:         path = Pathname.new(Pathname.pwd)
51:         path = path + args[1]
52:         filename = path.to_s
53:         if(args[1] =~ /\/$/ or args[1] =~ /\.$/)
54:           path = path + filename = filename + "/" + File.basename(url)
55:         end
56:       end
57:       File.open(filename, 'w') {|f| f.write(content) }
58:     else
59:       puts "Illegal arguments: " + args[1..100].join(" ")
60:       puts "#{$0}: usage '#{$0} get remote-url [local]"
61:     end
62:   end

TODO

 - Handle glob (ie *.gif) => Tell user to quote to avoid shell glob: dav get "*.html"

[Source]

    # File lib/davclient/davcli.rb, line 39
39:   def self.get(args)
40: 
41:     puts "DEBUG:"
42:     if(args.size == 1 or args.size == 2 )
43:       url = args[0]
44:       content =  WebDAV.get(url)
45:       filename = ""
46:       if(args.size == 1)
47:         filename = File.basename(url)
48:       else
49:         # Handle relative paths in local filenames or local dir
50:         path = Pathname.new(Pathname.pwd)
51:         path = path + args[1]
52:         filename = path.to_s
53:         if(args[1] =~ /\/$/ or args[1] =~ /\.$/)
54:           path = path + filename = filename + "/" + File.basename(url)
55:         end
56:       end
57:       File.open(filename, 'w') {|f| f.write(content) }
58:     else
59:       puts "Illegal arguments: " + args[1..100].join(" ")
60:       puts "#{$0}: usage '#{$0} get remote-url [local]"
61:     end
62:   end

[Source]

     # File lib/davclient/davcli.rb, line 175
175:   def self.ls(args)
176:     LsCLI.ls(args)
177:   end

[Source]

     # File lib/davclient/davcli.rb, line 175
175:   def self.ls(args)
176:     LsCLI.ls(args)
177:   end

[Source]

     # File lib/davclient/davcli.rb, line 126
126:   def self.mkcol(args)
127:     if(show_help?(args))
128:       puts "Usage: #{$0} mkcol [url|remote-path]"
129:       puts
130:       puts "Create collection (folder) on remote server."
131:       puts "The command 'mkdir' is an alias for 'mkcol'."
132:       puts
133:       puts "Examples: "
134:       puts "     #{$0} mkcol new_collection"
135:       puts "     #{$0} mkcol https://www.webdav.org/new_collection/"
136:       puts "     #{$0} mkcol ../new_collection"
137:       puts
138:       exit
139:     end
140:     if(args.size == 1 )
141:       if( args[0] =~ /^http/ || WebDAV.CWURL )
142:         WebDAV.mkcol(args[0])
143:       else
144:         puts "Error: #{$0} mkcol: No working url set. Use '#{$0} cd url' to set url."
145:       end
146:     else
147:       puts "#{$0}: usage '#{$0} mkcol [url|path]"
148:     end
149:   end

[Source]

     # File lib/davclient/davcli.rb, line 126
126:   def self.mkcol(args)
127:     if(show_help?(args))
128:       puts "Usage: #{$0} mkcol [url|remote-path]"
129:       puts
130:       puts "Create collection (folder) on remote server."
131:       puts "The command 'mkdir' is an alias for 'mkcol'."
132:       puts
133:       puts "Examples: "
134:       puts "     #{$0} mkcol new_collection"
135:       puts "     #{$0} mkcol https://www.webdav.org/new_collection/"
136:       puts "     #{$0} mkcol ../new_collection"
137:       puts
138:       exit
139:     end
140:     if(args.size == 1 )
141:       if( args[0] =~ /^http/ || WebDAV.CWURL )
142:         WebDAV.mkcol(args[0])
143:       else
144:         puts "Error: #{$0} mkcol: No working url set. Use '#{$0} cd url' to set url."
145:       end
146:     else
147:       puts "#{$0}: usage '#{$0} mkcol [url|path]"
148:     end
149:   end

[Source]

     # File lib/davclient/davcli.rb, line 190
190:   def self.mv(args)
191:     if(args.size == 2 )
192:       WebDAV.mv(args[0], args[1])
193:     else
194:       puts "Usage '#{$0} copy mv dest"
195:       puts
196:       puts "Move resources on remote server."
197:     end
198:   end

[Source]

     # File lib/davclient/davcli.rb, line 190
190:   def self.mv(args)
191:     if(args.size == 2 )
192:       WebDAV.mv(args[0], args[1])
193:     else
194:       puts "Usage '#{$0} copy mv dest"
195:       puts
196:       puts "Move resources on remote server."
197:     end
198:   end

[Source]

     # File lib/davclient/davcli.rb, line 161
161:   def self.options(args)
162:     if((args.size == 0 or args.size == 1) and !show_help?(args))
163:       puts WebDAV.options(args[0])
164:     else
165:       puts "Usage: #{$0} options [url]"
166:       puts
167:       puts "Prints remote server options and http headers. "
168:     end
169:   end

[Source]

     # File lib/davclient/davcli.rb, line 161
161:   def self.options(args)
162:     if((args.size == 0 or args.size == 1) and !show_help?(args))
163:       puts WebDAV.options(args[0])
164:     else
165:       puts "Usage: #{$0} options [url]"
166:       puts
167:       puts "Prints remote server options and http headers. "
168:     end
169:   end

[Source]

     # File lib/davclient/davcli.rb, line 200
200:   def self.print_dav_usage
201:     puts "usage: #{$0} COMMAND [ARGS]"
202:     puts ""
203:     puts "Available #{$0} commands:"
204:     puts "   ls        List files on webdav server"
205:     puts "   pwd       Print current working url"
206:     puts "   cd        Change current working url"
207:     puts "   cp        Copy resource"
208:     puts "   mv        Move resource"
209:     puts "   rm        Remove resource"
210:     puts "   cat       Print content of resource"
211:     puts "   mkdir     Create remote collection (directory) (mkcol alias)"
212:     puts "   get       Download resource"
213:     puts "   put       Upload local file"
214:     puts "   propfind  Print webdav properties for url"
215:     puts "   mkcol     Make collection"
216:     puts "   options   Display webservers WebDAV options"
217:     puts "   edit      Edit contents of remote file with editor"
218:     puts ""
219:     puts "See '#{$0} COMMAND -h' for more information on a specific command."
220:     exit
221:   end

[Source]

     # File lib/davclient/davcli.rb, line 200
200:   def self.print_dav_usage
201:     puts "usage: #{$0} COMMAND [ARGS]"
202:     puts ""
203:     puts "Available #{$0} commands:"
204:     puts "   ls        List files on webdav server"
205:     puts "   pwd       Print current working url"
206:     puts "   cd        Change current working url"
207:     puts "   cp        Copy resource"
208:     puts "   mv        Move resource"
209:     puts "   rm        Remove resource"
210:     puts "   cat       Print content of resource"
211:     puts "   mkdir     Create remote collection (directory) (mkcol alias)"
212:     puts "   get       Download resource"
213:     puts "   put       Upload local file"
214:     puts "   propfind  Print webdav properties for url"
215:     puts "   mkcol     Make collection"
216:     puts "   options   Display webservers WebDAV options"
217:     puts "   edit      Edit contents of remote file with editor"
218:     puts ""
219:     puts "See '#{$0} COMMAND -h' for more information on a specific command."
220:     exit
221:   end

[Source]

    # File lib/davclient/davcli.rb, line 9
 9:   def self.print_edit_usage
10:     puts "Usage: #{$0} edit [url|resource-name]"
11:     puts
12:     puts "Edit remote file in editor. File is transfered back to "
13:     puts "server after execution of editor is ended. "
14:     puts
15:   end

[Source]

    # File lib/davclient/davcli.rb, line 9
 9:   def self.print_edit_usage
10:     puts "Usage: #{$0} edit [url|resource-name]"
11:     puts
12:     puts "Edit remote file in editor. File is transfered back to "
13:     puts "server after execution of editor is ended. "
14:     puts
15:   end

[Source]

     # File lib/davclient/davcli.rb, line 171
171:   def self.propfind(args)
172:     PropfindCLI.propfind(args)
173:   end

[Source]

     # File lib/davclient/davcli.rb, line 171
171:   def self.propfind(args)
172:     PropfindCLI.propfind(args)
173:   end

[Source]

    # File lib/davclient/davcli.rb, line 85
85:   def self.pwd(args)
86:     if(show_help?(args))
87:       puts "Usage: #{$0} pwd"
88:       puts ""
89:       puts "Print current working url."
90:       exit
91:     end
92:     cwurl = WebDAV.CWURL
93:     if(cwurl)
94:       puts cwurl
95:     else
96:       puts "#{$0}: No working url set. Use 'dav cd url' to set url"
97:     end
98: 
99:   end

[Source]

    # File lib/davclient/davcli.rb, line 85
85:   def self.pwd(args)
86:     if(show_help?(args))
87:       puts "Usage: #{$0} pwd"
88:       puts ""
89:       puts "Print current working url."
90:       exit
91:     end
92:     cwurl = WebDAV.CWURL
93:     if(cwurl)
94:       puts cwurl
95:     else
96:       puts "#{$0}: No working url set. Use 'dav cd url' to set url"
97:     end
98: 
99:   end

[Source]

    # File lib/davclient/davcli.rb, line 79
79:   def self.show_help?(args)
80:     return (args.grep("-?").size > 0 or
81:             args.grep("-h").size > 0 or
82:             args.grep("--help").size > 0 )
83:   end

[Source]

    # File lib/davclient/davcli.rb, line 79
79:   def self.show_help?(args)
80:     return (args.grep("-?").size > 0 or
81:             args.grep("-h").size > 0 or
82:             args.grep("--help").size > 0 )
83:   end

[Validate]