Class: Vman::Client
- Inherits:
-
Object
- Object
- Vman::Client
- Defined in:
- lib/vman.rb
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
File.('~/.vman.json')
- ATTRS =
[:bucket_uri, :local_dir]
Instance Method Summary collapse
- #diff(args) ⇒ Object
-
#initialize(args = ARGV) ⇒ Client
constructor
A new instance of Client.
- #pull(args) ⇒ Object
- #push(args) ⇒ Object
Constructor Details
#initialize(args = ARGV) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 |
# File 'lib/vman.rb', line 14 def initialize(args = ARGV) @prompt = TTY::Prompt.new @config = validate_config @bucket_uri = @config['bucket_uri'] @local_dir = @config['local_dir'] || Dir.pwd parse_args(args) end |
Instance Method Details
#diff(args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vman.rb', line 31 def diff(args) from, to = @local_dir, @bucket_uri action = 'push' if args.shift == '-r' to, from, action = from, to, 'pull' end cmd = "aws s3 sync #{from} #{to} --dryrun" @prompt.warn("Showing file diff for a #{action} from \'#{from}\' to \'#{to}\'\n") @prompt.warn(`#{cmd}`) end |
#pull(args) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/vman.rb', line 45 def pull(args) cmd = "aws s3 sync #{@bucket_uri} #{@local_dir}" sub_cmd = args.shift cmd += ' --dryrun' unless sub_cmd == '-f' @prompt.warn("Pulling changes from remote bucket \'#{@bucket_uri}\' to #{@local_dir}.") @prompt.warn("This will overwrite local changes!") sub_cmd == '-f' ? @prompt.ok(`#{cmd}`) : @prompt.warn(`#{cmd}`) end |
#push(args) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/vman.rb', line 22 def push(args) cmd = "aws s3 sync #{@local_dir} #{@bucket_uri}" sub_cmd = args.shift cmd += ' --dryrun' unless sub_cmd == '-f' @prompt.warn("Pushing changes from #{@local_dir} to remote bucket \'#{@bucket_uri}\'") sub_cmd == '-f' ? @prompt.ok(`#{cmd}`) : @prompt.warn(`#{cmd}`) end |