Class: Knj::Cmd_gen
Overview
This class holds various methods to generate commands for command-line-purpose.
Class Method Summary collapse
-
.rsync(args) ⇒ Object
Generates rsync commands as strings.
-
.tar(args) ⇒ Object
Generates tar commands.
Class Method Details
.rsync(args) ⇒ Object
Generates rsync commands as strings.
Examples
Knj::Cmd_gen.rsync(
:bin => "/usr/bin/rsync",
:verbose => 2,
:ssh => true,
:port => 10022,
:delete => true,
:exclude => "cache",
:user => "username",
:host => "mydomain.com",
:dir_host => "/home/username/sync_path",
:dir_local => "/home/otheruser/sync_path"
) #=> <String>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/knj/cmd_gen.rb', line 17 def self.rsync(args) cmd = "" if args[:bin] cmd << args[:bin] else cmd << "rsync" end cmd << " -az" if args[:verbose] 1.upto(args[:verbose]) do cmd << "v" end end if args[:ssh] cmd << " -e ssh" if args[:port] cmd << " --rsh='ssh -p #{args[:port]}'" end end if args[:delete] cmd << " --delete" end if args[:exclude] args[:exclude].each do |dir| cmd << " --exclude \"#{dir}\"" end end cmd << " \"#{args[:user]}@#{args[:host]}:#{args[:dir_host]}\" \"#{args[:dir_local]}\"" return cmd end |
.tar(args) ⇒ Object
Generates tar commands.
Examples
Knj::Cmd_gen.tar(
:bin => "/usr/bin/tar",
:gzip => true,
:extract => false,
:file => true,
:create => true,
:verbose => 1,
:archive_path => "~/myarchive.tar.gz",
:paths => ["~/mylib1", "~/mylib2", "~/mylib3"]
) #=> <String>
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/knj/cmd_gen.rb', line 69 def self.tar(args) cmd = "" if args[:bin] cmd << args[:bin] else cmd << "tar" end cmd << " " cmd << "z"if args[:gzip] cmd << "x" if args[:extract] cmd << "f" if args[:file] cmd << "c" if args[:create] if args[:verbose] 1.upto(args[:verbose]) do cmd << "v" end end cmd << " \"#{args[:archive_path]}\"" args[:paths].each do |path| cmd << " \"#{path}\"" end return cmd end |