Sha256: 30baa773a83be82c37b6188205d1d0fb74e3aab342ebabbc799c8042428a49a3

Contents?: true

Size: 1.79 KB

Versions: 10

Compression:

Stored size: 1.79 KB

Contents

command "list spreadsheets" do |c|
  c.syntax = "#{$datapimp_cli} list spreadsheets"
  c.description = "list the spreadsheets which can be used as datasources"

  c.option '--type TYPE', String, "What type of source data is this? #{ Datapimp::Sync.data_source_types.join(", ") }"
  c.option '--filter PATTERN', String, "Filter the titles by the specified pattern"

  Datapimp::Cli.accepts_keys_for(c, :google, :dropbox)

  c.action do |args, options|
    puts "\nKey / Argument\t\tTitle"
    puts "============\t\t==========="
    lines = Datapimp::Sync.google.spreadsheets.map do |sheet|
      "#{ sheet.key }\t\t#{ sheet.title }"
    end

    lines = lines.grep(/#{options.filter}/) if options.filter.to_s.length > 0

    lines.each {|l| puts(l) }

    if lines.length > 0
      puts "\n\nExample:"
      puts "====="
      puts "#{$datapimp_cli} sync data #{ lines.first.split(/\t/).first } --type google-spreadsheet"
      puts "\n\n"
    end
  end
end

command "list folders" do |c|
  c.syntax= "#{$datapimp_cli} list folders [OPTIONS]"
  c.description= "lists folders in a remote service"

  c.option '--type SERVICE', String, 'Which service to search: dropbox, google, amazon'
  c.option '--filter PATTERN', nil, 'Filter the results matching PATTERN'

  c.action do |args, options|
    type = options.type.to_sym

    case
    when type == :dropbox
      puts "Path\n===\n"
      Datapimp::Sync.dropbox.ls(*([options.filter].compact)).each do |entry|
        puts entry.path if entry.is_dir
      end
    when type == :google
      puts "Collection\n====\n"
      Datapimp::Sync.google.api.collections.each do |collection|
        puts collection.title
      end
    when type == :amazon
      puts "Bucket\n====\n"
      Datapimp::Sync.amazon.storage.directories.each do |dir|
        puts dir.key
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
datapimp-1.2.11 lib/datapimp/cli/list.rb
datapimp-1.2.10 lib/datapimp/cli/list.rb
datapimp-1.2.9 lib/datapimp/cli/list.rb
datapimp-1.2.8 lib/datapimp/cli/list.rb
datapimp-1.2.7 lib/datapimp/cli/list.rb
datapimp-1.2.6 lib/datapimp/cli/list.rb
datapimp-1.2.5 lib/datapimp/cli/list.rb
datapimp-1.2.4 lib/datapimp/cli/list.rb
datapimp-1.2.3 lib/datapimp/cli/list.rb
datapimp-1.2.2 lib/datapimp/cli/list.rb