ASSETS.cli.config do |cnf| # rubocop:disable Metrics/BlockLength cnf.options_set do |options_set, options| # rubocop:disable Metrics/BlockLength options_set.add("--help", "Offers a HELP") do |options, session| conf = ASSETS.cli.config active = proc do |opt| if (there = SCR.get_arg(opt)) refine = SCR.get_arg(opt, with_param: true) end refine || there end if (hpf = active.call("-filters")) puts conf.people_filters.help(refine: hpf) end if (hif = active.call("-input-filters")) puts conf.input_filters.help(refine: hif) end if (ho = active.call("-options")) puts conf.options_set.help(refine: ho) end if (huc = active.call("-usecases")) puts conf.usecases.help(refine: huc) end help_str = [ "Please specify one of the below:", " -filters to display available filters on people", " -input-filters to display available filters on input data", " -options to dislpay available options", " -usecases to display available usecases", "TIPS:", " * You may specify the usecase to know its specific options by: -usecase_name --help -options", " * You may specify a refinement to show specific information only: --help -usecases tags" ].join("\n") puts help_str unless hpf || hif || ho || huc exit end desc = "Redirect Standard Ouput to file" options_set.add("-stdout", desc) do |options, session| file = SCR.get_arg("-stdout", with_param: true) || "output.txt" $stdout.reopen(file, "w+") end desc = "Skips the check of the headers" options_set.add("-skip-header-check", desc) do |options, session| options.deep_merge!(input: {header_check: {skip: true}}) end desc = "It requires the order of the headers to be as expected (exact match required)" options_set.add("-header-order-check", desc) do |options, session| options.deep_merge!(input: {header_check: {order: true}}) end desc = "It raises an exception if any header issues are detected" options_set.add("-require-valid-header", desc) do |options, session| options.deep_merge!(input: {header_check: {must_be_valid: true}}) end desc = "Fix the current session to work with this schema" options_set.add("-schema-id", desc) do |options, session| sch_name = SCR.get_arg("-schema-id", with_param: true) sch_id = session.schemas.to_id(sch_name) unless sch_id msg = "You need to specify a correct schema id or name. '#{sch_name}' does not exist" session.log(:error) { msg } exit(1) end options.deep_merge!(people: {filter: {details: {schema_id: sch_id}}}) session.log(:info) { "Setting schema #{session.schemas.to_name(sch_id)}" } session.schema = sch_id end desc = "Used to be used to specify the input file or folder when using -get-partial. " desc << "It can also be useful to obtain `-get-partial` of people base on `:export` use cases (i.e. -people-to-csv)" options_set.add("-entries-from", desc) do |options, session| options.deep_merge!(input: {entries_from: true}) end desc = "Used to specify the input file encoding" options_set.add("-input-encoding", desc) do |options, session| if encoding = SCR.get_arg("-input-encoding", with_param: true) options.deep_merge!(input: {file: {encoding: encoding}}) end end desc = "Do not load any people for this run." options_set.add("-no-people", desc) do |options, session| options.deep_merge!(people: { get: false }) end desc = "Used to only get the people from the input file. " desc << "It will also include their current and new supervisors." options_set.add("-get-partial", desc) do |options, session| options.deep_merge!(people: { get: { from: :remote, type: :partial } }) end desc = "Locally cache all the people manager by retrieving from the server" options_set.add("-get-people", desc) do |options, session| options.deep_merge!(people: { get: { from: :remote, type: :full } }) end desc = "Saves the requests's body even though running in dry-run (-simulate)" options_set.add("-save-requests", desc) do |options, session| options.deep_merge!(requests: {backup: true}) end desc = "Used to specify the cache file of people to be used. " desc << "It is useful to use as people reference those stored in cached file diffrent to the last one." options_set.add("-people-from-backup", desc) do |options, session| file = SCR.get_file("-people-from-backup", required: true, should_exist: true) options.deep_merge!(people: { get: { from: :local, type: :file, file: file } }) end desc = "Used to export to a csv the final people (after processing). " desc << "It is useful analyse the data after a -dry-run (-simulate)." options_set.add("-processed-people-to-csv", desc) do |options, session| file = SCR.get_file("-processed-people-to-csv", required: true, should_exist: false) options.deep_merge!(report: {people: {csv: file}}) end desc = "Runs in dry-run (no requests sent to server)" options_set.add(["-dry-run", "-simulate"], desc) do |options, session| options[:dry_run] = true options[:simulate] = true session.config.dry_run! end desc = "Specifies the target API key space (i.e. uat, dev, etc.). " desc << "Use with CAUTION !!!" options_set.add('-space', desc) do |options, session| next unless space = SCR.get_arg('-space', with_param: true) options.deep_merge!(api: {space: space.to_sym}) end desc = "It specifies the type of batch to be used (default: ':batch')" options_set.add("-batch-mode", desc) do |options, session| mode_in = SCR.get_arg("-batch-mode", with_param: true) mode_str = mode_in.to_s.downcase mode_sym = %i[batch job].find do |md| next true if md.to_s == mode_str md.to_s == mode_str.gsub(':', '') end unless mode_sym session.log(:warn) { "Unknown job_mode: #{mode_in}. Switching to default: ':batch'" } mode_sym = :batch end options.deep_merge!(workflow: {batch: {mode: mode_sym}}) end desc = "Runs runs post_launch cases even if in dry-run" options_set.add("-run-postlaunch", desc) do |options, session| options.deep_merge!(post_launch: {run: true}) end desc = "(careful with this option) This will include everybody as part of the update (including those that are api excluded). " desc << "Only launch with this option when only api excluded people are included in your update." options_set.add("-include-excluded", desc) do |options| options.deep_merge!(include: {excluded: true}) end desc = "Includes in API updates ONLY people that evaluate true as people excluded from periodic upates." options_set.add("-include-only-excluded", desc) do |options| options.deep_merge!(include: {excluded: {only: true}}) end desc = "Ignores threshold limitations on requests for this session (skip batch belt)" options_set.add("-skip-batch-policy", desc) do |options| options.deep_merge!(skip: {batch_policy: true}) end desc = "Will not run the api policies defined for the enviro" options_set.add("-skip-api-policies", desc) do |options| options.deep_merge!(skip: {api_policies: true}) end options_set.add("-feed-only-stats", "Shows only stats when giving feedback") do |options| options.deep_merge!(feedback: {only_stats: true}) end desc = "Deprecated: used to be used to avoid reloading people after launch" options[:end_get] = true options_set.add("-no-get", desc) do |options| options[:end_get] = false end desc = "Force search mode to 'strict' when pairing input entries with existing people." desc << " Besides id and external_id it will not try to find by email unless external_id is not specified" options_set.add("-search-strict", desc) do |options| options.deep_merge!(search: {strict: true}) end desc = "Search mode that will try to find people using email when id and external_id have failed" desc << " This option could identify existing people by their email addresses" desc << " (it should not be used in orgs where multiple people usually have the same email address)" options_set.add("-search-soft", desc) do |options| options.deep_merge!(search: { soft: true, strict: false }) end desc = "Prevent email to be sent (experimental)" options_set.add("-no-email", desc) do |options| options.deep_merge!(workflow: {no_email: true}) end desc = "Silence notifications on account creation or invites" options_set.add(["-no-invites", "-exclude-invites"], desc) do |options| options.merge!(send_invites: false) end desc = "People with account will be reinvited if they haven't accepted the invitation" options_set.add("-send-invites", desc) do |options| options.merge!(send_invites: true) end options_set.add("-exclude-core", "Core input data is not used on the update") do |options| options.deep_merge!(exclude: {core: true}) end options_set.add("-exclude-filter-tags", "filter_tags is not set with the input data") do |options| options.deep_merge!(exclude: {filter_tags: true}) end options_set.add("-exclude-external-id", "external_id is not set with the input data") do |options| options.deep_merge!(exclude: {external_id: true}) end options_set.add("-exclude-supervisor", "supervisor_id is not set with the input data") do |options| options.deep_merge!(exclude: {supervisor: true}) end options_set.add("-exclude-email", "email is not set with the input data") do |options| options.deep_merge!(exclude: {email: true}) end options_set.add("-exclude-name", "name is not set with the input data") do |options| options.deep_merge!(exclude: {name: true}) end options_set.add("-exclude-details", "Details are not set with the input data") do |options| options.deep_merge!(exclude: {details: true}) end options_set.add("-exclude-account", "Account is not set with the input data") do |options| options.deep_merge!(exclude: {account: true}) end options_set.add("-exclude-policy-groups", "policy_group_ids is not set with the input data") do |options| options.deep_merge!(exclude: {policy_groups: true}) end options_set.add("-default-tag", "default_tag is not set with the input data") do |options| options.deep_merge!(exclude: {default_tag: true}) end options_set.add("-exclude-abilities", "permissions_custom is not set with the input data") do |options| options.deep_merge!(exclude: {abilities: true}) end options_set.add("-exclude-login-providers", "login_provider_ids is not set with the input data") do |options| options.deep_merge!(exclude: {login_providers: true}) end end end