diff --git a/config/src/lib.rs b/config/src/lib.rs index 15340ee..8ff25be 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -84,7 +84,7 @@ impl AqoraConfig { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct AqoraUseCaseConfig { - pub competition: String, + pub competition: Option, pub data: PathBuf, pub template: Option, pub generator: PathStr<'static>, @@ -103,7 +103,7 @@ pub struct LayerConfig { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct AqoraSubmissionConfig { - pub competition: String, + pub competition: Option, pub entity: Option, pub refs: HashMap>, } diff --git a/src/commands/install.rs b/src/commands/install.rs index 12c75e0..5f70708 100644 --- a/src/commands/install.rs +++ b/src/commands/install.rs @@ -36,6 +36,7 @@ pub struct Install { pub uv: Option, #[arg(long)] pub upgrade: bool, + pub competition: Option, } pub async fn install_submission(args: Install, project: PyProject) -> Result<()> { @@ -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::(get_competition_use_case::Variables { - slug: config.competition.clone(), - }) + .send::(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", ) })?; diff --git a/src/commands/upload.rs b/src/commands/upload.rs index 27a7f08..2f1b5aa 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -27,6 +27,7 @@ pub struct Upload { pub project: PathBuf, #[arg(long)] pub uv: Option, + pub competition: Option, } #[derive(GraphQLQuery)] @@ -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( @@ -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 {