Class: Omega::CLI
- Inherits:
-
Object
- Object
- Omega::CLI
- Includes:
- Contest
- Defined in:
- lib/omega/cli.rb,
lib/omega/cli/contest.rb
Defined Under Namespace
Modules: Contest
Constant Summary collapse
- SUB_COMMANDS =
%w[ register-users user scoreboard create-contest add-problem sources help ].freeze
- GENERAL_DOC =
%( OmegaUp CLI. Developed by OMIJal https://github.com/omijal/omegaup-cli. Tool for interacting with omegaup from CLI and available throug ruby gems. Commands: - register-users Add a user or a bunch of users to the a contest. - copy-problems Adds prob from another contest - user Generates a dump of the user data in yml format. - scoreboard Gets contest scoreboard with users and score. - clarifications Gets contest clarifications. - sources Downloads all code sources into path Parametes: --contest Contest name --user Username or email --user-file A file path containing a list of user one per line without header --open Filter to only open clarifications --path Path to store results Setup: You need to add two env variables with your omegaup credentials. OMEGAUP_URL *Optional* This is intended for development purpose, it will target to https://omegaup.com by default. OMEGAUP_USER *Required* Your OmegaUp Username or Email OMEGAUP_PASS *Required* Your OmegaUp Password )
Instance Attribute Summary collapse
-
#omega ⇒ Object
readonly
Returns the value of attribute omega.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(_) ⇒ CLI
constructor
A new instance of CLI.
- #login ⇒ Object
- #print_help ⇒ Object
Methods included from Contest
#add_problem, #clarifications, #copy_problems, #copy_users, #download_sources, #register_user, #register_users, #scoreboard, #user_data
Constructor Details
#initialize(_) ⇒ CLI
Returns a new instance of CLI.
51 52 53 54 55 56 57 58 59 60 61 62 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/omega/cli.rb', line 51 def initialize(_) @cmd = ARGV.shift @cmd_opts = case @cmd when 'copy-problems' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string opt :from, 'Another constest that allows to clone users from another contest', type: :string end when 'add-problem' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string opt :problem, 'Problem name', type: :string end when 'register-users' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string opt :user, 'Username or email', type: :string opt :from, 'Another constest that allows to clone users from another contest', type: :string opt :user_file, 'A file containing the users list one per line and without header', type: :string end when 'user' Optimist. do opt :user, 'Username or email', type: :string end when 'scoreboard' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string end when 'clarifications' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string opt :open, 'Filter to only open clars' end when 'sources' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string opt :path, 'Path to store results', type: :string end # when 'create-contest' # Optimist.options do # opt :contest, 'Contest ShortName or identifier', type: :string # end # when 'add-problem' # Optimist.options do # opt :contest, 'Contest ShortName or identifier', type: :string # opt :problem, type: :string # end else print_help exit(0) end end |
Instance Attribute Details
#omega ⇒ Object (readonly)
Returns the value of attribute omega.
9 10 11 |
# File 'lib/omega/cli.rb', line 9 def omega @omega end |
Instance Method Details
#execute ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/omega/cli.rb', line 118 def execute login case @cmd when 'register-users' register_user(@cmd_opts[:contest], @cmd_opts[:user]) if @cmd_opts[:user] register_users(@cmd_opts[:contest], @cmd_opts[:user_file]) if @cmd_opts[:user_file] copy_users(@cmd_opts[:contest], @cmd_opts[:from]) if @cmd_opts[:from] when 'user' user_data(@cmd_opts[:user]) when 'scoreboard' scoreboard(@cmd_opts[:contest]) when 'clarifications' clarifications(@cmd_opts[:contest], @cmd_opts[:open]) when 'sources' download_sources(@cmd_opts[:contest], @cmd_opts[:path]) when 'copy-problems' copy_problems(@cmd_opts[:contest], @cmd_opts[:from]) when 'add-problem' add_problem(@cmd_opts[:contest], @cmd_opts[:problem]) end end |
#login ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/omega/cli.rb', line 105 def login config = { 'omega' => { 'endpoint' => ENV['OMEGAUP_URL'] || 'https://omegaup.com', 'user' => ENV.fetch('OMEGAUP_USER', nil), 'pass' => ENV.fetch('OMEGAUP_PASS', nil) } } @omega = Omega::Client.new(config['omega']) @omega.login end |
#print_help ⇒ Object
47 48 49 |
# File 'lib/omega/cli.rb', line 47 def print_help puts GENERAL_DOC end |