Class: Gdrive::CLI
- Inherits:
-
Thor
- Object
- Thor
- Gdrive::CLI
- Defined in:
- lib/utilities/gdrive/cli.rb
Direct Known Subclasses
Instance Method Summary collapse
Instance Method Details
#get(file_id) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/utilities/gdrive/cli.rb', line 79 def get(file_id) result = tool.get_file_content(file_id) puts "📄 #{result[:name]}" puts " Type: #{result[:mime_type]}" puts " Size: #{format_bytes(result[:size])}" puts if [:output] File.write([:output], result[:content]) puts "✅ Content saved to #{[:output]}" else puts "Content:" puts result[:content] end rescue RuntimeError => e warn "❌ Failed to get file content: #{e.}" exit 1 end |
#list ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/utilities/gdrive/cli.rb', line 54 def list result = tool.list_files(max_results: [:max_results]) files = result[:files] if files.empty? puts "📂 No files found in Google Drive" else puts "📂 Recent #{result[:count]} file(s):" files.each_with_index do |file, index| puts " #{index + 1}. #{file[:name]}" puts " ID: #{file[:id]}" puts " Type: #{file[:mime_type]}" puts " Size: #{format_bytes(file[:size])}" puts " Modified: #{file[:modified_time]}" puts " Link: #{file[:web_view_link]}" puts end end rescue RuntimeError => e warn "❌ Failed to list files: #{e.}" exit 1 end |
#search(query) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/utilities/gdrive/cli.rb', line 29 def search(query) result = tool.search_files(query, max_results: [:max_results]) files = result[:files] if files.empty? puts "🔍 No files found matching '#{query}'" else puts "🔍 Found #{result[:count]} file(s) matching '#{query}':" files.each_with_index do |file, index| puts " #{index + 1}. #{file[:name]}" puts " ID: #{file[:id]}" puts " Type: #{file[:mime_type]}" puts " Size: #{format_bytes(file[:size])}" puts " Modified: #{file[:modified_time]}" puts " Link: #{file[:web_view_link]}" puts end end rescue RuntimeError => e warn "❌ Failed to search files: #{e.}" exit 1 end |
#test ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/utilities/gdrive/cli.rb', line 10 def test response = tool.test_connection if response[:ok] puts "✅ Successfully connected to Google Drive" puts " User: #{response[:user]} (#{response[:email]})" if response[:storage_used] && response[:storage_limit] puts " Storage: #{format_bytes(response[:storage_used])} / #{format_bytes(response[:storage_limit])}" end else warn "❌ Connection test failed" end rescue RuntimeError => e puts "❌ Failed to connect to Google Drive: #{e.}" exit 1 end |