Class: Flydata::Command::Base
Direct Known Subclasses
Conf, Crontab, Encrypt, Kill_all, Login, Restart, Routine, Sender, Setlogdel, Setup, Start, Status, Stop, Sync, Version
Instance Attribute Summary collapse
Instance Method Summary
collapse
#before_logging, #log_error_stderr, #log_info_stdout, #log_warn_stderr
Constructor Details
#initialize(options = Slop.new) ⇒ Base
Returns a new instance of Base.
9
10
11
12
|
# File 'lib/flydata/command/base.rb', line 9
def initialize(options = Slop.new)
@api_client = ApiClient.instance
@opts = options
end
|
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
13
14
15
|
# File 'lib/flydata/command/base.rb', line 13
def opts
@opts
end
|
Instance Method Details
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/flydata/command/base.rb', line 80
def ask_input_table_name
input = nil
loop do
log_info_stdout("Input a table name.")
say(">> ")
input = gets.strip
if input =~ /^[a-zA-Z0-9_]+$/
break
else
puts "Please enter a valid table name."
end
end
log_info(">> #{input}")
input
end
|
#ask_yes_no(message, default_yes = true) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/flydata/command/base.rb', line 41
def ask_yes_no(message, default_yes=true)
suffix = default_yes ? "(Y/n)" : "(y/n)"
prompt = "#{message} #{suffix}: "
if opts && opts.yes? log_info_stdout("#{prompt}Yes")
return true
end
loop do
ans = ask(prompt)
return true if default_yes and ans == ''
if ans.size > 0
case ans[0].downcase
when 'y'
log_info("#{prompt}Yes")
return true
when 'n'
log_info("#{prompt}No")
return false
end
end
log_warn_stderr(" ! Please answer y[es] or n[o]")
newline
end
end
|
#choose_one(message, prompt, menu_list, value_list = []) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/flydata/command/base.rb', line 66
def choose_one(message, prompt, , value_list=[])
choice = nil
value_list = unless .size == value_list.size
log_info_stdout(message) if message
choose do ||
.index = :number
.index_suffix = ") "
.select_by = :index
.prompt = prompt ? prompt : ">> "
.choices(*) {|item| choice = value_list[.index(item)]}
end
log_info_stdout(" -> #{choice}")
choice
end
|
#flydata ⇒ Object
14
|
# File 'lib/flydata/command/base.rb', line 14
def flydata; @api_client end
|
#newline ⇒ Object
37
|
# File 'lib/flydata/command/base.rb', line 37
def newline; puts end
|
#register_crontab ⇒ Object
29
30
31
32
33
34
|
# File 'lib/flydata/command/base.rb', line 29
def register_crontab
data_entries = retrieve_data_entries
if data_entries.any?{|e| e['log_deletion']}
Flydata::Command::Crontab.new.run
end
end
|
#retrieve_data_entries ⇒ Object
#separator(str = "=") ⇒ Object
38
39
40
|
# File 'lib/flydata/command/base.rb', line 38
def separator(str="=")
puts str * 64
end
|