Class: SdrClient::RedesignedClient::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/sdr_client/redesigned_client/cli.rb,
lib/sdr_client/redesigned_client/cli/update.rb,
lib/sdr_client/redesigned_client/cli/credentials.rb

Overview

The SDR command-line interface

Defined Under Namespace

Classes: Credentials, Update

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_urlObject



30
31
32
# File 'lib/sdr_client/redesigned_client/cli.rb', line 30

def self.default_url
  'https://sdr-api-prod.stanford.edu'
end

.exit_on_failure?Boolean

Make sure Thor commands preserve exit statuses



18
19
20
# File 'lib/sdr_client/redesigned_client/cli.rb', line 18

def self.exit_on_failure?
  true
end

.handle_no_command_error(command) ⇒ Object

Print out help and exit with error code if command not found



23
24
25
26
27
28
# File 'lib/sdr_client/redesigned_client/cli.rb', line 23

def self.handle_no_command_error(command)
  puts "Command '#{command}' not found, displaying help:"
  puts
  puts help
  exit(1)
end

Instance Method Details

#deposit(*files) ⇒ Object



110
111
112
# File 'lib/sdr_client/redesigned_client/cli.rb', line 110

def deposit(*files)
  register_or_deposit(files: files, accession: true)
end

#get(druid) ⇒ Object



39
40
41
# File 'lib/sdr_client/redesigned_client/cli.rb', line 39

def get(druid)
  say client.find(object_id: druid)
end

#register(*files) ⇒ Object



134
135
136
# File 'lib/sdr_client/redesigned_client/cli.rb', line 134

def register(*files)
  register_or_deposit(files: files, accession: false)
end

#update(druid) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/sdr_client/redesigned_client/cli.rb', line 63

def update(druid)
  validate_druid!(druid)
  # Make sure client is configured
  client
  job_id = Update.run(druid, **options)
  if options[:skip_polling]
    say "job ID #{job_id} queued (not polling because `-s` flag was supplied)"
    return
  end

  # the extra args to `say` prevent appending a newline
  say('SDR is processing your request.', nil, false)

  job_status = client.job_status(job_id: job_id)
  job_status.wait_until_complete { say('.', nil, false) }

  if job_status.complete?
    if job_status.errors
      say_error " errored! #{job_status.errors}"
    else
      say " success! (druid: #{job_status.druid})"
    end
  else
    say_error " job #{job_id} did not complete\n#{job_status.result.inspect}"
  end
end

#versionObject



44
45
46
# File 'lib/sdr_client/redesigned_client/cli.rb', line 44

def version
  say VERSION
end