lib/tsks/cli.rb in tsks-0.0.3 vs lib/tsks/cli.rb in tsks-0.0.4
- old
+ new
@@ -10,10 +10,15 @@
def self.setup_folder
@setup_folder
end
+ desc "version", ""
+ def version
+ puts "tsks #{Tsks::VERSION}"
+ end
+
desc "init", "Setup tsks folder and storage"
def init
if File.directory? CLI.setup_folder
return puts "tsks was already initialized."
end
@@ -92,11 +97,11 @@
Tsks::Actions.update_tsks_with_uuid res[:user_id]
puts "Succesfully registered."
elsif res && res[:status_code] == 409
puts "This e-mail is already registered."
end
- rescue Errno::ECONNREFUSED
+ rescue Errno::ECONNREFUSED, SocketError
puts "Failed to connect to the API."
rescue JSON::ParserError
puts "Error on reading data from the API."
end
end
@@ -119,11 +124,11 @@
Tsks::Actions.update_tsks_with_uuid res[:user_id]
puts "Succesfully logged in."
elsif res && res[:status_code] == 403
puts "Invalid e-mail or password."
end
- rescue Errno::ECONNREFUSED
+ rescue Errno::ECONNREFUSED, SocketError
puts "Failed to connect to the API."
rescue JSON::ParserError
puts "Error on reading data from the API."
end
end
@@ -137,14 +142,16 @@
if !File.exist? File.join CLI.setup_folder, "token"
return puts "Please, login before try to sync."
end
user_id = File.read File.join CLI.setup_folder, "user_id"
+ token = File.read File.join CLI.setup_folder, "token"
Tsks::Actions.update_tsks_with_uuid user_id
+ Tsks::Actions.update_server_for_removed_tsks token
+ Tsks::Storage.delete_removed_uuids
local_tsks = Tsks::Storage.select_all local_id=false
- token = File.read File.join CLI.setup_folder, "token"
remote_tsks = []
begin
get_res = Tsks::Request.get "/tsks", token
if get_res[:tsks]
for tsk in get_res[:tsks]
@@ -165,13 +172,25 @@
end
puts "Your tsks were succesfully synchronized."
end
end
- rescue Errno::ECONNREFUSED
+ rescue Errno::ECONNREFUSED, SocketError
puts "Failed to connect to the API."
rescue JSON::ParserError
puts "Error on reading data from the API."
+ end
+ end
+
+ desc "remove ID", "..."
+ def remove id
+ if !File.directory? CLI.setup_folder
+ return puts "tsks was not initialized yet."
+ end
+
+ op_status = Tsks::Storage.delete id
+ if !op_status
+ puts "The specified tsk do not exist."
end
end
end
end