Class: Snapsync::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/snapsync/cli.rb

Instance Method Summary collapse

Instance Method Details

#auto_syncObject



118
119
120
121
122
# File 'lib/snapsync/cli.rb', line 118

def auto_sync
    auto = AutoSync.new(SnapperConfig.default_config_dir)
    auto.load_config(Pathname.new(options[:config_file]))
    auto.run
end

#cleanup(dir) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/snapsync/cli.rb', line 49

def cleanup(dir)
    handle_class_options

    target = LocalTarget.new(Pathname.new(dir))
    if target.cleanup
        target.cleanup.cleanup(target, dry_run: options[:dry_run])
    else
        Snapsync.info "#{target.sync_policy.class.name} policy set, nothing to do"
    end
end

#destroy(dir) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/snapsync/cli.rb', line 104

def destroy(dir)
    handle_class_options
    target_dir = Pathname.new(dir)
    target = LocalTarget.new(target_dir, create_if_needed: false)
    snapshots = target.each_snapshot.to_a
    snapshots.sort_by(&:num).each do |s|
        target.delete(s)
    end
    target_dir.rmtree
end

#init(dir) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/snapsync/cli.rb', line 61

def init(dir)
    dir = Pathname.new(dir)
    if !dir.exist?
        dir.mkpath
    end

    target = LocalTarget.new(dir)
    target.change_policy('default', Hash.new)
    target.write_config
end

#policy(dir, type, *options) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/snapsync/cli.rb', line 87

def policy(dir, type, *options)
    handle_class_options

    dir = Pathname.new(dir)
    if !dir.exist?
        dir.mkpath
    end

    target = LocalTarget.new(dir)
    target.change_policy(type, options)
    target.write_config
end

#sync(config_name, dir) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/snapsync/cli.rb', line 28

def sync(config_name, dir)
    handle_class_options

    config = config_from_name(config_name)
    target = LocalTarget.new(Pathname.new(dir))
    LocalSync.new(config, target).sync
end

#sync_all(dir) ⇒ Object



40
41
42
43
44
45
# File 'lib/snapsync/cli.rb', line 40

def sync_all(dir)
    handle_class_options

    op = SyncAll.new(dir, config_dir: SnapperConfig.default_config_dir, autoclean: options[:autoclean])
    op.run
end