Sha256: 3731b94b4655bf7c660818bd241c0cd2bf456847fea4af53862b7bf7836d2b17

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift 'lib'
require 'optparse'

options = {}
global = OptionParser.new do |opts|
  opts.on('--service-url URL', 'Connect to the host at this URL') do |url|
    options[:url] = url
  end
  opts.on('-h', '--help', 'Display this screen') do
    puts <<~HELP
      DESCRIPTION:
        The SDR Command Line Interface is a tool to interact with the Stanford Digital Repository.

      SYNOPSIS:
        sdr [options] <command>

      OPTIONS:
        --service-url (string)
        Override the command's default URL with the given URL.

        -h, --help
        Displays this screen

      COMMANDS
        deposit
        deposit files to the SDR

        login
        Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token

    HELP
    exit
  end
end

global.order!
command = ARGV.shift

subcommands = {
  'deposit' => OptionParser.new do |opts|
    opts.on('--label LABEL', 'The object label') do |label|
      options[:label] = label
    end

    opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
      options[:apo] = apo
    end
    opts.on('--collection COLLECTION', 'The druid identifier of the collection object') do |collection|
      options[:collection] = collection
    end

    opts.on('--catkey CATKEY', 'The catkey for this item') do |catkey|
      options[:catkey] = catkey
    end

    opts.on('--source-id SOURCE_ID', 'The source id for this object') do |source_id|
      options[:source_id] = source_id
    end

    opts.on('-h', '--help', 'Display this screen') do
      puts opts
      exit
    end
  end,
  'login' => OptionParser.new
}

unless subcommands.key?(command)
  puts "unknown command '#{command}'"
  exit
end

subcommands[command].order!

require 'sdr_client'
options[:files] = ARGV unless ARGV.empty?
SdrClient::CLI.start(command, options)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sdr-client-0.4.0 exe/sdr
sdr-client-0.3.1 exe/sdr
sdr-client-0.3.0 exe/sdr
sdr-client-0.2.1 exe/sdr
sdr-client-0.2.0 exe/sdr