|
| 1 | +require "thor" |
| 2 | +require_relative "process_ldap" |
| 3 | + |
| 4 | +class CLI < Thor |
| 5 | + def self.exit_on_failure? |
| 6 | + true |
| 7 | + end |
| 8 | + |
| 9 | + desc "full", "processes all of the users in mcommunity" |
| 10 | + method_option :output_directory, type: :string, required: false, default: S.output_directory, desc: "Path to directory for output files" |
| 11 | + method_option :base_name, type: :string, required: false, default: "patron_full_#{Date.today.strftime("%Y%m%d")}", desc: "Basename for files put in the output directory" |
| 12 | + method_option :size, type: :numeric, required: false, desc: "The maximum number of results to request" |
| 13 | + def full |
| 14 | + new_options = { |
| 15 | + size: options[:size], |
| 16 | + base_name: options[:base_name], |
| 17 | + output_directory: options[:output_directory] |
| 18 | + } |
| 19 | + ProcessLdap.new(**new_options).process |
| 20 | + end |
| 21 | + |
| 22 | + desc "daily FROM_DATE", "Processes all users in mcommunity modified or created after the FROM_DATE 000000 UTC. For full coverage, the FROM_DATE for a daily cronjob should be yesterday." |
| 23 | + method_option :output_directory, type: :string, required: false, default: S.output_directory, desc: "Path to directory for output files" |
| 24 | + method_option :base_name, type: :string, required: false, default: "patron_daily_#{Date.today.strftime("%Y%m%d")}", desc: "Basename for files put in the output directory" |
| 25 | + method_option :size, type: :numeric, required: false, desc: "The maximum number of results to request" |
| 26 | + def daily(from_date) |
| 27 | + new_options = { |
| 28 | + date: format_date(from_date), |
| 29 | + base_name: options[:base_name], |
| 30 | + output_directory: options[:output_directory], |
| 31 | + size: options[:size] |
| 32 | + } |
| 33 | + ProcessLdapDaily.new(**new_options).process |
| 34 | + end |
| 35 | + |
| 36 | + desc "range", "processes users for a given date range" |
| 37 | + method_option :start_date, type: :string, required: true |
| 38 | + method_option :end_date, type: :string, required: false, desc: "The end of the date range. Inclusive. If not given, it defaults to whatever start_date is." |
| 39 | + method_option :size, type: :numeric, required: false, desc: "The maximum number of results to request" |
| 40 | + method_option :output_directory, type: :string, required: false, default: S.output_directory, desc: "Path to directory for output files" |
| 41 | + method_option :base_name, type: :string, required: false, desc: "Basename for files put in the output directory; default is patron_range_YYYYMMDD_to_YYYYMMDD" |
| 42 | + def range |
| 43 | + new_options = { |
| 44 | + start_date: format_date(options[:start_date]), |
| 45 | + end_date: format_date(options[:end_date] || options[:start_date]), |
| 46 | + size: options[:size], |
| 47 | + output_directory: options[:output_directory] |
| 48 | + } |
| 49 | + |
| 50 | + new_options[:base_name] = options[:base_name] || "patron_range_#{new_options[:start_date]}_to_#{new_options[:end_date]}" |
| 51 | + |
| 52 | + ProcessLdapModifyDateRange.new(**new_options).process |
| 53 | + end |
| 54 | + |
| 55 | + desc "one UNIQNAME", "returns the xml for the uniqname" |
| 56 | + def one(uniqname) |
| 57 | + ProcessLdapOneUser.new(uniqname: uniqname).process |
| 58 | + end |
| 59 | + |
| 60 | + desc "ldap UNIQNAME", "returns the ldap info for a user" |
| 61 | + def ldap(uniqname) |
| 62 | + ProcessLdapOneUser.new(uniqname: uniqname).ldap_output |
| 63 | + end |
| 64 | + |
| 65 | + private |
| 66 | + |
| 67 | + no_commands do |
| 68 | + def format_date(date) |
| 69 | + date = DateTime.parse(date) if date.is_a? String |
| 70 | + date.strftime("%Y%m%d") |
| 71 | + rescue Date::Error |
| 72 | + abort("ERROR: parameter/option #{date} must be a valid date string\n") |
| 73 | + end |
| 74 | + end |
| 75 | +end |
0 commit comments