class Revit::CLI
Rev's cli interface
@author [brwnrclse]
Public Instance Methods
__print_version()
click to toggle source
# File lib/revit/cli.rb, line 18 def __print_version puts VERSION end
create(path)
click to toggle source
# File lib/revit/cli.rb, line 41 def create(path) rev_id = nil paths = path.split paths ||= options[:list_files] if options[:list_files] spinner = TTY::Spinner.new('[:spinner] :msg', format: :bouncing_ball) spinner.update(msg: 'Creating a rev...') spinner.run do rev_id = RevAPI.create_rev(options[:title], options[:description]) end spinner.success(Paint['rev created', :green]) docs = Util.collect_docs(paths, spinner) successful_docs = [] spinner.update(msg: 'Uploading docs to rev api') docs.each do |doc| spinner.run do doc_id = RevAPI.create_doc(doc.doc_name, doc.has_diff, rev_id, doc.syntax) # TODO: Add in Auth.signFile call # TODO: Add in RevAPI.create_s3Resource call spinner.success(Paint['doc uploaded to api', :green]) # Collect successful doc_ids incase of failure successful_docs.insert(doc_id) end end puts "\nrev available at #{Paint["wver.vaemoi.co/rev/#{rev_id}", :green]}" rescue Errno::ECONNRESET, Errno::EINVAL, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout, Net::ProtocolError, Revit::BaemptyException, Revit::GraphQLDataException, Revit::GraphQLValidationException => e Revit::LOGGER.error(e.message) spinner.error(e.message) successful_docs.each do |id| RevAPI.delete_doc(id) end RevAPI.delete_rev(rev_id) end
login()
click to toggle source
# File lib/revit/cli.rb, line 94 def login puts "Login here for your token:\n\n#{Paint[Auth.auth_code_url, :green]}" puts "\n\n" auth_code = Thor::Shell::Basic.new.ask('Enter your auth code => ') spinner = TTY::Spinner.new('[:spinner] :msg', format: :bouncing_ball) spinner.update(msg: 'Logging in') spinner.run do begin auth_token = Auth.auth_token(auth_code) user_id = RevAPI.signin_user(auth_token[:auth0_id]) if user_id.nil? spinner.update(msg: 'User not found! Creating...') user_id = RevAPI.create_user(auth_token[:auth0_id]) spinner.success(Paint['User created and Logged in', :green]) end Revit::STORE.transaction do |store| store[:access_token] = auth_token[:access_token].strip store[:expires] = auth_token[:expires] store[:auth0_id] = auth_token[:auth0_id].strip store[:user_id] = user_id end spinner.success(Paint['Login successful :)', :green]) rescue Errno::ECONNRESET, Errno::EINVAL, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::OpenTimeout, Net::ProtocolError, Revit::GraphQLDataException, Revit::GraphQLValidationException => e Revit::LOGGER.error(e.message) spinner.error(Paint[e.message, :red]) end end end