Class: Autosftp::CLI

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

Instance Method Summary collapse

Instance Method Details

#delete(word) ⇒ Object



79
80
81
# File 'lib/autosftp/cli.rb', line 79

def delete(word)
  Autosftp::FileAccess.delete word
end

#initObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/autosftp/cli.rb', line 98

def init
  init_file = Autosftp::FileAccess
  if true == init_file.exist?
    if yes? "File exists. Overwrite the file? [y/n]"
      init_file.create
      puts 'overwite!!! (' + init_file.path + ')'
    else
      puts 'cancel'
    end
  else
    init_file.create
    puts 'create!!! (' + init_file.path + ')'
  end
end

#listObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/autosftp/cli.rb', line 84

def list()
  Autosftp::FileAccess.read.each do |key, value|
    puts "\n\#{key}:\n  host:        \#{value[:host]}\n  local_path:  \#{value[:local_path]}\n  remote_path: \#{value[:remote_path]}\n\n"
  end
end

#set(word) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/autosftp/cli.rb', line 46

def set(word)
  ssh_hash = {}

  begin
    puts "[username@host:port]"
    ssh_str = STDIN.gets.chomp
    if false == Autosftp::Connection.check?(ssh_str)
      puts "is not [username@host:port]"
      exit
    end

    ssh_hash = Autosftp::Connection.explode ssh_str

    puts "password:"
    ssh_hash[:password] = STDIN.noecho(&:gets).chomp

    puts "remote path:"
    ssh_hash[:remote_path] = STDIN.gets.chomp

    puts "local path: --If you enter a blank, the current directory is set"
    ssh_hash[:local_path] = STDIN.gets.chomp
    if '' == ssh_hash[:local_path]
      ssh_hash[:local_path] = Dir.pwd
      puts ssh_hash[:local_path]
    end

    Autosftp::FileAccess.save word, ssh_hash

  rescue Interrupt
  end
end

#start(*word) ⇒ Object



12
13
14
15
16
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
# File 'lib/autosftp/cli.rb', line 12

def start(*word)
  if false == Autosftp::FileAccess.exist?
    puts "is not .autosftp \n $ autosftp init"
    exit
  end

  conf = Autosftp::FileAccess.read
  if !conf[word[0]]
    puts "is not setting \n $ autosftp set [remote name]"
    exit
  elsif
    setting = conf[word[0]]
    word.delete_at(0)
  end

  if 0 < word.size
    dir = word.map {|a| a.to_s + "**/*"}
  else
    dir = '**/*'
  end

  permission = {}
  if options[:chmod]
    permission[:dir]  = options[:chmod]
    permission[:file] = options[:chmod]
  else
    permission[:dir]  = 755
    permission[:file] = 644
  end

  Autosftp::Monitor.start setting, dir, permission
end