lib/ayadn/alias.rb in ayadn-1.8.2 vs lib/ayadn/alias.rb in ayadn-2.0
- old
+ new
@@ -6,26 +6,26 @@
map "add" => :create
long_desc Descriptions.alias_create
def create(*args)
begin
init
+ status = Status.new
unless args.empty?
channel, channel_alias = args[0], args[1]
else
- abort(Status.wrong_arguments)
+ status.wrong_arguments
+ exit
end
if channel.is_integer?
Databases.create_alias(channel, channel_alias)
Logs.rec.info "Added alias '#{channel_alias}' for channel #{channel}."
- puts Status.done
+ status.done
else
- puts Status.error_missing_channel_id
+ status.error_missing_channel_id
end
rescue => e
Errors.global_error({error: e, caller: caller, data: [args]})
- ensure
- Databases.close_all
end
end
desc "delete ALIAS", "Deletes a previously created alias"
map "remove" => :delete
@@ -34,86 +34,58 @@
begin
init
unless args.empty?
Databases.delete_alias(args[0])
Logs.rec.info "Deleted alias '#{args[0]}'."
- puts Status.done
+ Status.new.done
else
- abort(Status.wrong_arguments)
+ Status.new.wrong_arguments
+ exit
end
rescue => e
Errors.global_error({error: e, caller: caller, data: [args]})
- ensure
- Databases.close_all
end
end
- desc "import DATABASE", "Imports an aliases database from a backed up Ayadn account"
- long_desc Descriptions.alias_import
- def import(database)
- begin
- init
- unless database.nil?
- new_db = File.realpath(database)
- else
- abort(Status.wrong_arguments)
- end
- if File.exist?(new_db)
- Databases.import_aliases(new_db)
- Logs.rec.info "Imported '#{new_db}' values in aliases database."
- puts Status.done
- else
- puts "\nFile '#{new_db}' doesn't exist.".color(:red)
- end
- rescue => e
- Errors.global_error({error: e, caller: caller, data: [database]})
- ensure
- Databases.close_all
- end
- end
-
desc "list", "List previously created aliases"
long_desc Descriptions.alias_list
option :raw, aliases: "-x", type: :boolean, desc: "Outputs the raw list in JSON"
+ option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
def list
begin
init
- list = Databases.aliases
+ Settings.options[:timeline][:compact] = true if options[:compact] == true
+ list = Databases.all_aliases
unless list.empty? || list.nil?
if options[:raw]
- h = {}
- list.each {|k,v| h[k] = v}
- puts h.to_json
+ puts list.to_json
else
View.new.page Workers.new.build_aliases_list(list)
end
else
- puts Status.empty_list
+ Status.new.empty_list
end
rescue => e
Errors.global_error({error: e, caller: caller, data: [options]})
- ensure
- Databases.close_all
end
end
desc "clear", "Clear your aliases database"
def clear
begin
init
- puts "\n\nAre you sure you want to erase all the content of your aliases database?\n\n[y/N]\n".color(:red)
+ status = Status.new
+ status.ask_clear_databases
input = STDIN.getch
if input == 'y' || input == 'Y'
Databases.clear_aliases
Logs.rec.info "Cleared the aliases database."
- puts Status.done
+ status.done
else
- abort Status.canceled
+ status.canceled
end
rescue => e
Errors.global_error({error: e, caller: caller, data: []})
- ensure
- Databases.close_all
end
end
private