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 help ].freeze
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
#register_user, #register_users, #scoreboard, #user_data
Constructor Details
#initialize(_) ⇒ CLI
Returns a new instance of CLI.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/omega/cli.rb', line 43 def initialize(_) @cmd = ARGV.shift @cmd_opts = case @cmd when 'register-users' Optimist. do opt :contest, 'Contest ShortName or identifier', type: :string opt :user, 'Username or email', 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 '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
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/omega/cli.rb', line 89 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] when 'user' user_data(@cmd_opts[:user]) when 'scoreboard' scoreboard(@cmd_opts[:contest]) end end |
#login ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/omega/cli.rb', line 76 def login config = { 'omega' => { 'endpoint' => ENV['OMEGAUP_URL'] || 'https://omegaup.com', 'user' => ENV['OMEGAUP_USER'], 'pass' => ENV['OMEGAUP_PASS'] } } @omega = Omega::Client.new(config['omega']) @omega.login end |
#print_help ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/omega/cli.rb', line 21 def print_help puts %( 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. - user Generates a dump of the user data in yml format. - scoreboard Gets contest scoreboard with users and score. Parametes: --contest Contest name --user Username or email --user_file A file path containing a list of user one per line without header 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://omegau.com by default. OMEGAUP_USER *Required* Your OmegaUp Username or Email OMEGAUP_PASS *Required* Your OmegaUp Password ) end |