change ask::string to string, and modify the display
This commit is contained in:
parent
777b1e41ad
commit
619d5afd8c
1 changed files with 47 additions and 47 deletions
94
lib/Cli.rb
94
lib/Cli.rb
|
@ -30,12 +30,12 @@ class Cli
|
||||||
# Create a new config file
|
# Create a new config file
|
||||||
# @args: lang -> the software language
|
# @args: lang -> the software language
|
||||||
def setup(lang)
|
def setup(lang)
|
||||||
puts "# #{I18n.t('cli.form.setup.title')}"
|
puts I18n.t('cli.form.setup.title')
|
||||||
puts "# --------------------"
|
puts '--------------------'
|
||||||
language = ask(I18n.t('cli.form.setup.lang', :lang => lang))
|
language = ask(I18n.t('cli.form.setup.lang', :lang => lang)).to_s
|
||||||
key = ask(I18n.t('cli.form.setup.gpg_key'))
|
key = ask(I18n.t('cli.form.setup.gpg_key')).to_s
|
||||||
file_gpg = ask(I18n.t('cli.form.setup.gpg_file', :home => Dir.home()))
|
file_gpg = ask(I18n.t('cli.form.setup.gpg_file', :home => Dir.home())).to_s
|
||||||
timeout_pwd = ask(I18n.t('cli.form.setup.timeout'))
|
timeout_pwd = ask(I18n.t('cli.form.setup.timeout')).to_s
|
||||||
|
|
||||||
if !File.exist?("#{APP_ROOT}/i18n/#{language}.yml")
|
if !File.exist?("#{APP_ROOT}/i18n/#{language}.yml")
|
||||||
language= 'en'
|
language= 'en'
|
||||||
|
@ -78,16 +78,16 @@ class Cli
|
||||||
# Display an item in the default format
|
# Display an item in the default format
|
||||||
# @args: item -> an array with the item information
|
# @args: item -> an array with the item information
|
||||||
def displayFormat(item)
|
def displayFormat(item)
|
||||||
puts "# --------------------"
|
puts '--------------------'
|
||||||
puts "# Id: #{item[MPW::ID]}"
|
puts "Id: #{item[MPW::ID]}"
|
||||||
puts "# #{I18n.t('cli.display.name')}: #{item[MPW::NAME]}"
|
puts "#{I18n.t('cli.display.name')}: #{item[MPW::NAME]}"
|
||||||
puts "# #{I18n.t('cli.display.group')}: #{item[MPW::GROUP]}"
|
puts "#{I18n.t('cli.display.group')}: #{item[MPW::GROUP]}"
|
||||||
puts "# #{I18n.t('cli.display.server')}: #{item[MPW::SERVER]}"
|
puts "#{I18n.t('cli.display.server')}: #{item[MPW::SERVER]}"
|
||||||
puts "# #{I18n.t('cli.display.protocol')}: #{item[MPW::PROTOCOL]}"
|
puts "#{I18n.t('cli.display.protocol')}: #{item[MPW::PROTOCOL]}"
|
||||||
puts "# #{I18n.t('cli.display.login')}: #{item[MPW::LOGIN]}"
|
puts "#{I18n.t('cli.display.login')}: #{item[MPW::LOGIN]}"
|
||||||
puts "# #{I18n.t('cli.display.password')}: #{item[MPW::PASSWORD]}"
|
puts "#{I18n.t('cli.display.password')}: #{item[MPW::PASSWORD]}"
|
||||||
puts "# #{I18n.t('cli.display.port')}: #{item[MPW::PORT]}"
|
puts "#{I18n.t('cli.display.port')}: #{item[MPW::PORT]}"
|
||||||
puts "# #{I18n.t('cli.display.comment')}: #{item[MPW::COMMENT]}"
|
puts "#{I18n.t('cli.display.comment')}: #{item[MPW::COMMENT]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display an item in the alternative format
|
# Display an item in the alternative format
|
||||||
|
@ -109,16 +109,16 @@ class Cli
|
||||||
# Form to add a new item
|
# Form to add a new item
|
||||||
def add()
|
def add()
|
||||||
row = Array.new()
|
row = Array.new()
|
||||||
puts "# #{I18n.t('cli.form.add.title')}"
|
puts I18n.t('cli.form.add.title')
|
||||||
puts "# --------------------"
|
puts '--------------------'
|
||||||
name = ask(I18n.t('cli.form.add.name'))
|
name = ask(I18n.t('cli.form.add.name')).to_s
|
||||||
group = ask(I18n.t('cli.form.add.group'))
|
group = ask(I18n.t('cli.form.add.group')).to_s
|
||||||
server = ask(I18n.t('cli.form.add.server'))
|
server = ask(I18n.t('cli.form.add.server')).to_s
|
||||||
protocol = ask(I18n.t('cli.form.add.protocol'))
|
protocol = ask(I18n.t('cli.form.add.protocol')).to_s
|
||||||
login = ask(I18n.t('cli.form.add.login'))
|
login = ask(I18n.t('cli.form.add.login')).to_s
|
||||||
passwd = ask(I18n.t('cli.form.add.password'))
|
passwd = ask(I18n.t('cli.form.add.password')).to_s
|
||||||
port = ask(I18n.t('cli.form.add.port'))
|
port = ask(I18n.t('cli.form.add.port')).to_s
|
||||||
comment = ask(I18n.t('cli.form.add.comment'))
|
comment = ask(I18n.t('cli.form.add.comment')).to_s
|
||||||
|
|
||||||
if @m.add(name, group, server, protocol, login, passwd, port, comment)
|
if @m.add(name, group, server, protocol, login, passwd, port, comment)
|
||||||
if @m.encrypt()
|
if @m.encrypt()
|
||||||
|
@ -137,16 +137,16 @@ class Cli
|
||||||
row = @m.searchById(id)
|
row = @m.searchById(id)
|
||||||
|
|
||||||
if not row.empty?
|
if not row.empty?
|
||||||
puts "# #{I18n.t('cli.form.update.title')}"
|
puts I18n.t('cli.form.update.title')
|
||||||
puts "# --------------------"
|
puts '--------------------'
|
||||||
name = ask(I18n.t('cli.form.update.name' , :name => row[MPW::NAME]))
|
name = ask(I18n.t('cli.form.update.name' , :name => row[MPW::NAME])).to_s
|
||||||
group = ask(I18n.t('cli.form.update.group' , :group => row[MPW::GROUP]))
|
group = ask(I18n.t('cli.form.update.group' , :group => row[MPW::GROUP])).to_s
|
||||||
server = ask(I18n.t('cli.form.update.server' , :server => row[MPW::SERVER]))
|
server = ask(I18n.t('cli.form.update.server' , :server => row[MPW::SERVER])).to_s
|
||||||
protocol = ask(I18n.t('cli.form.update.protocol', :protocol => row[MPW::PROTOCOL]))
|
protocol = ask(I18n.t('cli.form.update.protocol', :protocol => row[MPW::PROTOCOL])).to_s
|
||||||
login = ask(I18n.t('cli.form.update.login' , :login => row[MPW::LOGIN]))
|
login = ask(I18n.t('cli.form.update.login' , :login => row[MPW::LOGIN])).to_s
|
||||||
passwd = ask(I18n.t('cli.form.update.password'))
|
passwd = ask(I18n.t('cli.form.update.password')).to_s
|
||||||
port = ask(I18n.t('cli.form.update.port' , :port => row[MPW::PORT]))
|
port = ask(I18n.t('cli.form.update.port' , :port => row[MPW::PORT])).to_s
|
||||||
comment = ask(I18n.t('cli.form.update.comment' , :comment => row[MPW::COMMENT]))
|
comment = ask(I18n.t('cli.form.update.comment' , :comment => row[MPW::COMMENT])).to_s
|
||||||
|
|
||||||
if @m.update(id, name, group, server, protocol, login, passwd, port, comment)
|
if @m.update(id, name, group, server, protocol, login, passwd, port, comment)
|
||||||
if @m.encrypt()
|
if @m.encrypt()
|
||||||
|
@ -172,7 +172,7 @@ class Cli
|
||||||
if result.length > 0
|
if result.length > 0
|
||||||
self.displayFormat(result)
|
self.displayFormat(result)
|
||||||
|
|
||||||
confirm = ask("#{I18n.t('cli.form.delete.ask', :id => id)} (y/N) ")
|
confirm = ask("#{I18n.t('cli.form.delete.ask', :id => id)} (y/N) ").to_s
|
||||||
if confirm =~ /^(y|yes|YES|Yes|Y)$/
|
if confirm =~ /^(y|yes|YES|Yes|Y)$/
|
||||||
force = true
|
force = true
|
||||||
end
|
end
|
||||||
|
@ -217,7 +217,7 @@ class Cli
|
||||||
self.displayFormat(r)
|
self.displayFormat(r)
|
||||||
end
|
end
|
||||||
|
|
||||||
confirm = ask("#{I18n.t('cli.form.import.ask', :file => file)} (y/N) ")
|
confirm = ask("#{I18n.t('cli.form.import.ask', :file => file)} (y/N) ").to_s
|
||||||
if confirm =~ /^(y|yes|YES|Yes|Y)$/
|
if confirm =~ /^(y|yes|YES|Yes|Y)$/
|
||||||
force = true
|
force = true
|
||||||
end
|
end
|
||||||
|
@ -279,15 +279,15 @@ class Cli
|
||||||
group = nil
|
group = nil
|
||||||
end
|
end
|
||||||
when 'help', 'h', '?'
|
when 'help', 'h', '?'
|
||||||
puts "# #{I18n.t('cli.interactive.option.title')}"
|
puts I18n.t('cli.interactive.option.title')
|
||||||
puts '# --------------------'
|
puts '--------------------'
|
||||||
puts "# display, show, d, s SEARCH #{I18n.t('cli.interactive.option.show')}"
|
puts "display, show, d, s SEARCH #{I18n.t('cli.interactive.option.show')}"
|
||||||
puts "# group, g #{I18n.t('cli.interactive.option.group')}"
|
puts "group, g #{I18n.t('cli.interactive.option.group')}"
|
||||||
puts "# add, a #{I18n.t('cli.interactive.option.add')}"
|
puts "add, a #{I18n.t('cli.interactive.option.add')}"
|
||||||
puts "# update, u ID #{I18n.t('cli.interactive.option.update')}"
|
puts "update, u ID #{I18n.t('cli.interactive.option.update')}"
|
||||||
puts "# remove, delete, r, d ID #{I18n.t('cli.interactive.option.remove')}"
|
puts "remove, delete, r, d ID #{I18n.t('cli.interactive.option.remove')}"
|
||||||
puts "# help, h, ? #{I18n.t('cli.interactive.option.help')}"
|
puts "help, h, ? #{I18n.t('cli.interactive.option.help')}"
|
||||||
puts "# quit, exit, q #{I18n.t('cli.interactive.option.quit')}"
|
puts "quit, exit, q #{I18n.t('cli.interactive.option.quit')}"
|
||||||
when 'quit', 'exit', 'q'
|
when 'quit', 'exit', 'q'
|
||||||
puts I18n.t('cli.interactive.goodbye')
|
puts I18n.t('cli.interactive.goodbye')
|
||||||
break
|
break
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue