lib/tsks/cli.rb in tsks-0.0.9 vs lib/tsks/cli.rb in tsks-0.0.10

- old
+ new

@@ -19,21 +19,21 @@ desc "version", "" def version puts "tsks #{Tsks::VERSION}" end - desc "init", "Setup tsks folder and storage" + desc "init", "setup tsks folder and storage" def init if File.directory? CLI.setup_folder return puts "tsks was already initialized." end Dir.mkdir CLI.setup_folder Tsks::Storage.init end - desc "add TSK", "Add a new tsk (Use --context to specify one e.g. Work)" + desc "add TSK", "add a new tsk (Use --context to specify one e.g. Work)" option :context def add tsk if !File.directory? CLI.setup_folder return puts "tsks was not initialized yet." end @@ -43,20 +43,20 @@ else Tsks::Storage.insert tsk end end - desc "done ID", "Mark a tsk you have already done" + desc "done ID", "mark a tsk you have already done" def done id if !File.directory? CLI.setup_folder return puts "tsks was not initialized yet." end Tsks::Storage.update id end - desc "list", "See all active tsks, filter by context or that are done" + desc "list", "see all active tsks, filter by context or that are done" option :done, type: :boolean option :context def list if !File.directory? CLI.setup_folder return puts "tsks was not initialized yet." @@ -78,81 +78,81 @@ for tsk in tsks tsk_status = Tsks::Actions.get_tsk_status tsk[:status] puts "#{tsk_status} | #{tsk[:local_id]} #{tsk[:tsk]} @#{tsk[:context]}" end else - puts "No tsks found." + puts "no tsks found." end end - desc "register", "Register an e-mail to be able to sync your tsks" + desc "register", "register an e-mail to be able to sync your tsks" option :email, required: true option :password, required: true def register if !File.directory? CLI.setup_folder return puts "tsks was not initialized yet." end begin res = Tsks::Request.post "/signup", {email: options[:email], - password: options[:password]} + password: options[:password]} if res && res[:ok] == true - File.write File.join(CLI.setup_folder, "token"), res[:auth_token] - File.write File.join(CLI.setup_folder, "user_id"), res[:user_id] - Tsks::Actions.update_tsks_with_uuid res[:user_id] - puts "Succesfully registered." + File.write File.join(CLI.setup_folder, "token"), res[:user][:auth_token] + File.write File.join(CLI.setup_folder, "user_id"), res[:user][:id] + Tsks::Actions.update_tsks_with_user_id res[:user][:id] + puts "succesfully registered." elsif res && res[:ok] == false - puts "This e-mail is already registered." + puts "this e-mail is already registered." end rescue Errno::ECONNREFUSED, SocketError - puts "Failed to connect to the API." + puts "failed to connect to API." rescue JSON::ParserError - puts "Error on reading data from the API." + puts "error on reading data from API." end end - desc "login", "Login to be able to sync your tsks" + desc "login", "login to be able to sync your tsks" option :email, required: true option :password, required: true def login if !File.directory? CLI.setup_folder return puts "tsks was not initialized yet." end begin res = Tsks::Request.post "/signin", {email: options[:email], - password: options[:password]} + password: options[:password]} if res && res[:ok] == true - File.write File.join(CLI.setup_folder, "token"), res[:auth_token] - File.write File.join(CLI.setup_folder, "user_id"), res[:user_id] - Tsks::Actions.update_tsks_with_uuid res[:user_id] - puts "Succesfully logged in." + File.write File.join(CLI.setup_folder, "token"), res[:user][:auth_token] + File.write File.join(CLI.setup_folder, "user_id"), res[:user][:id] + Tsks::Actions.update_tsks_with_user_id res[:user][:id] + puts "succesfully logged in." elsif res && res[:ok] == false - puts "Invalid e-mail or password." + puts "invalid e-mail or password." end rescue Errno::ECONNREFUSED, SocketError - puts "Failed to connect to the API." + puts "failed to connect to API." rescue JSON::ParserError - puts "Error on reading data from the API." + puts "error on reading data from API." end end - desc "sync", "Synchronize your tsks" + desc "sync", "synchronize your tsks" def sync if !File.directory? CLI.setup_folder return puts "tsks was not initialized yet." end if !File.exist? File.join CLI.setup_folder, "token" - return puts "Please, login before try to sync." + 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_tsks_with_user_id user_id Tsks::Actions.update_server_for_removed_tsks token Tsks::Storage.delete_removed_uuids local_tsks = Tsks::Storage.select_all local_id=false remote_tsks = [] @@ -176,17 +176,17 @@ remote_tsks_to_storage = remote_tsks - local_tsks if remote_tsks_to_storage.count > 0 Tsks::Storage.insert_many remote_tsks_to_storage end - puts "Your tsks were succesfully synchronized." + puts "your tsks were succesfully synchronized." end end rescue Errno::ECONNREFUSED, SocketError - puts "Failed to connect to the API." + puts "failed to connect to API." rescue JSON::ParserError - puts "Error on reading data from the API." + puts "error on reading data from API." end end desc "remove ID", "..." def remove id @@ -194,10 +194,10 @@ return puts "tsks was not initialized yet." end op_status = Tsks::Storage.delete id if !op_status - puts "The specified tsk do not exist." + puts "the specified tsk do not exist." end end end end