mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-27 15:43:04 +00:00
fix import and export to yaml
This commit is contained in:
parent
568a8514cf
commit
30f52dfe92
3 changed files with 7 additions and 7 deletions
|
@ -172,7 +172,7 @@ module MPW
|
||||||
# @args: file -> file where you export the data
|
# @args: file -> file where you export the data
|
||||||
# type -> udata type
|
# type -> udata type
|
||||||
# @rtrn: true if export work
|
# @rtrn: true if export work
|
||||||
def export(file, type=:csv)
|
def export(file, type=:yaml)
|
||||||
case type
|
case type
|
||||||
when :csv
|
when :csv
|
||||||
CSV.open(file, 'w', write_headers: true,
|
CSV.open(file, 'w', write_headers: true,
|
||||||
|
@ -200,7 +200,7 @@ module MPW
|
||||||
# @args: file -> path to file import
|
# @args: file -> path to file import
|
||||||
# type -> udata type
|
# type -> udata type
|
||||||
# @rtrn: true if the import work
|
# @rtrn: true if the import work
|
||||||
def import(file, type=:csv)
|
def import(file, type=:yaml)
|
||||||
case type
|
case type
|
||||||
when :csv
|
when :csv
|
||||||
CSV.foreach(file, {headers: true}) do |row|
|
CSV.foreach(file, {headers: true}) do |row|
|
||||||
|
|
|
@ -307,7 +307,7 @@ class Cli
|
||||||
|
|
||||||
# Export the items in a CSV file
|
# Export the items in a CSV file
|
||||||
# @args: file -> the destination file
|
# @args: file -> the destination file
|
||||||
def export(file, type)
|
def export(file, type=:yaml)
|
||||||
if @mpw.export(file, type)
|
if @mpw.export(file, type)
|
||||||
puts "The export in #{file} is succesfull!"
|
puts "The export in #{file} is succesfull!"
|
||||||
else
|
else
|
||||||
|
@ -319,10 +319,10 @@ class Cli
|
||||||
# Import items from a CSV file
|
# Import items from a CSV file
|
||||||
# @args: file -> the import file
|
# @args: file -> the import file
|
||||||
# force -> no resquest a validation
|
# force -> no resquest a validation
|
||||||
def import(file, force=false)
|
def import(file, type=:yaml, force=false)
|
||||||
|
|
||||||
if not force
|
if not force
|
||||||
result = @mpw.import_preview(file)
|
result = @mpw.import_preview(file, type)
|
||||||
if result.is_a?(Array) and not result.empty?
|
if result.is_a?(Array) and not result.empty?
|
||||||
result.each do |r|
|
result.each do |r|
|
||||||
displayFormat(r)
|
displayFormat(r)
|
||||||
|
@ -338,7 +338,7 @@ class Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
if force
|
if force
|
||||||
if @mpw.import(file) and @mpw.encrypt
|
if @mpw.import(file, type) and @mpw.encrypt
|
||||||
sync
|
sync
|
||||||
puts I18n.t('form.import.valid')
|
puts I18n.t('form.import.valid')
|
||||||
else
|
else
|
||||||
|
|
2
mpw
2
mpw
|
@ -153,7 +153,7 @@ elsif not options[:export].nil?
|
||||||
|
|
||||||
# Add a new item
|
# Add a new item
|
||||||
elsif not options[:import].nil?
|
elsif not options[:import].nil?
|
||||||
cli.import(options[:import], options[:force])
|
cli.import(options[:import], options[:type], options[:force])
|
||||||
|
|
||||||
# Interactive mode
|
# Interactive mode
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue