Repository: AmbientRun/Ambient
File: app/src/cli/mod.rs (Rust)

Code before:
            Commands::View { project_args, .. } => Some(project_args),
            Commands::Join { .. } => None,
            Commands::Assets { .. } => None,
        }
    }
    /// Extract host-relevant state only
    pub fn host(&self) -> Option<&HostCli> {
        match &self.command {
            Commands::New { .. } => None,
            Commands::Run { host_args, .. } => Some(host_args),
            Commands::Build { .. } => None,
            Commands::Deploy { .. } => None,
            Commands::Serve { host_args, .. } => Some(host_args),
            Commands::View { .. } => None,
            Commands::Join { .. } => None,
            Commands::Assets { .. } => None,
        }
    }
    pub fn use_release_build(&self) -> bool {
        match &self.command {
            Commands::New { .. } => false,
            Commands::Run { project_args, .. } => project_args.is_release().unwrap_or(false),
            Commands::Build { project_args, .. } => project_args.is_release().unwrap_or(false),
            Commands::Deploy { project_args, .. } => project_args.is_release().unwrap_or(true),
            Commands::Serve { project_args, .. } => project_args.is_release().unwrap_or(true),
            Commands::View { project_args, .. } => project_args.is_release().unwrap_or(false),
            Commands::Join { .. } => false,
            Commands::Assets { .. } => false,
        }
    }
}

impl ProjectCli {
    pub fn is_release(&self) -> Option<bool> {
        match (self.debug, self.release) {
            (true, false) => Some(false),
            (false, true) => Some(true),
            (false, false) => None,
            (true, true) => {
                // clap's conflict_with should prevent this from happening
                panic!("debug and release are mutually exclusive")
            }
        }
    }
}


Review comment (suggestion):
You might be able to do `Commands::Run { project_args, .. } | Commands::Build { project_args, .. }` etc - as long as the bound variables are the same, you can group them together.

Code after:
            Commands::View { project_args, .. } => Some(project_args),
            Commands::Join { .. } => None,
            Commands::Assets { .. } => None,
        }
    }
    /// Extract host-relevant state only
    pub fn host(&self) -> Option<&HostCli> {
        match &self.command {
            Commands::New { .. } => None,
            Commands::Run { host_args, .. } => Some(host_args),
            Commands::Build { .. } => None,
            Commands::Deploy { .. } => None,
            Commands::Serve { host_args, .. } => Some(host_args),
            Commands::View { .. } => None,
            Commands::Join { .. } => None,
            Commands::Assets { .. } => None,
        }
    }
    pub fn use_release_build(&self) -> bool {
        match &self.command {
            Commands::Deploy { project_args, .. } | Commands::Serve { project_args, .. } => {
                project_args.is_release().unwrap_or(true)
            }
            Commands::Run { project_args, .. }
            | Commands::Build { project_args, .. }
            | Commands::View { project_args, .. } => project_args.is_release().unwrap_or(false),
            Commands::New { .. } | Commands::Join { .. } | Commands::Assets { .. } => false,
        }
    }
}

impl ProjectCli {
    pub fn is_release(&self) -> Option<bool> {
        match (self.debug, self.release) {
            (true, false) => Some(false),
            (false, true) => Some(true),
            (false, false) => None,
            (true, true) => {
                // clap's conflict_with should prevent this from happening
                panic!("debug and release are mutually exclusive")
            }
        }
    }
}