Skip to content

Commit

Permalink
make competition overrideable by command line
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopesculian committed Feb 21, 2024
1 parent 177d0d6 commit 948be81
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl AqoraConfig {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AqoraUseCaseConfig {
pub competition: String,
pub competition: Option<String>,
pub data: PathBuf,
pub template: Option<PathBuf>,
pub generator: PathStr<'static>,
Expand All @@ -103,7 +103,7 @@ pub struct LayerConfig {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AqoraSubmissionConfig {
pub competition: String,
pub competition: Option<String>,
pub entity: Option<String>,
pub refs: HashMap<String, PathStr<'static>>,
}
Expand Down
17 changes: 13 additions & 4 deletions src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Install {
pub uv: Option<PathBuf>,
#[arg(long)]
pub upgrade: bool,
pub competition: Option<String>,
}

pub async fn install_submission(args: Install, project: PyProject) -> Result<()> {
Expand Down Expand Up @@ -67,15 +68,23 @@ pub async fn install_submission(args: Install, project: PyProject) -> Result<()>
)
})?;

let slug = args
.competition
.as_ref()
.or(config.competition.as_ref())
.ok_or_else(|| {
error::user(
"No competition provided",
"Please specify a competition in either the pyproject.toml or the command line",
)
})?;
let competition = client
.send::<GetCompetitionUseCase>(get_competition_use_case::Variables {
slug: config.competition.clone(),
})
.send::<GetCompetitionUseCase>(get_competition_use_case::Variables { slug: slug.clone() })
.await?
.competition_by_slug
.ok_or_else(|| {
error::user(
&format!("Competition '{}' not found", config.competition),
&format!("Competition '{slug}' not found"),
"Please make sure the competition exists",
)
})?;
Expand Down
25 changes: 23 additions & 2 deletions src/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Upload {
pub project: PathBuf,
#[arg(long)]
pub uv: Option<PathBuf>,
pub competition: Option<String>,
}

#[derive(GraphQLQuery)]
Expand Down Expand Up @@ -201,7 +202,17 @@ pub async fn upload_use_case(args: Upload, project: PyProject) -> Result<()> {
)
})?;

let competition_id = get_competition_id_by_slug(&client, &config.competition).await?;
let slug = args
.competition
.as_ref()
.or(config.competition.as_ref())
.ok_or_else(|| {
error::user(
"No competition provided",
"Please specify a competition in either the pyproject.toml or the command line",
)
})?;
let competition_id = get_competition_id_by_slug(&client, slug).await?;

let version = project.version().ok_or_else(|| {
error::user(
Expand Down Expand Up @@ -446,7 +457,17 @@ pub async fn upload_submission(args: Upload, project: PyProject) -> Result<()> {
)
})?;

let competition_id = get_competition_id_by_slug(&client, &config.competition).await?;
let slug = args
.competition
.as_ref()
.or(config.competition.as_ref())
.ok_or_else(|| {
error::user(
"No competition provided",
"Please specify a competition in either the pyproject.toml or the command line",
)
})?;
let competition_id = get_competition_id_by_slug(&client, slug).await?;
let entity_id = if let Some(username) = &config.entity {
get_entity_id_by_username(&client, username).await?
} else {
Expand Down

0 comments on commit 948be81

Please sign in to comment.