/// Creates a provider archive using an initial architecture target, provider, and signing keys
Creates a provider archive using an initial architecture target, provider, and signing keys
Creates a provider archive using an initial architecture target provider and signing keys
pub(crate) fn handle_create(cmd: CreateCommand) -> Result<String> {
    let mut par = ProviderArchive::new(
        &cmd.capid,
        &cmd.name,
        &cmd.vendor,
        cmd.revision,
        cmd.version,
    );
    let mut f = File::open(cmd.binary.clone())?;
    let mut lib = Vec::new();
    f.read_to_end(&mut lib)?;
    let issuer = extract_keypair(
        cmd.issuer,
        Some(cmd.binary.clone()),
        cmd.directory.clone(),
        KeyPairType::Account,
        cmd.disable_keygen,
    )?;
    let subject = extract_keypair(
        cmd.subject,
        Some(cmd.binary.clone()),
        cmd.directory,
        KeyPairType::Service,
        cmd.disable_keygen,
    )?;
    par.add_library(&cmd.arch, &lib).map_err(convert_error)?;
    let extension = if cmd.compress { ".par.gz" } else { ".par" };
    let outfile = match cmd.destination {
        Some(path) => path,
        None => format!(
            "{}{}",
            PathBuf::from(cmd.binary.clone())
                .file_stem()
                .unwrap()
                .to_str()
                .unwrap()
                .to_string(),
            extension
        ),
    };
    Ok(
        if par
            .write(&outfile, &issuer, &subject, cmd.compress)
            .is_err()
        {
            format!(
                "Error writing PAR. Please ensure directory {:?} exists",
                PathBuf::from(outfile.clone()).parent().unwrap(),
            )
        } else {
            format_output(
                format!("Successfully created archive {}", outfile),
                json!({"result": "success", "file": outfile}),
                &cmd.output.kind,
            )
        },
    )
}
pub ( crate ) fn handle_create ( cmd : CreateCommand ) -> Result < String > { let mut par = ProviderArchive :: new ( & cmd . capid , & cmd . name , & cmd . vendor , cmd . revision , cmd . version , ) ; let mut f = File :: open ( cmd . binary . clone ( ) ) ? ; let mut lib = Vec :: new ( ) ; f . read_to_end ( & mut lib ) ? ; let issuer = extract_keypair ( cmd . issuer , Some ( cmd . binary . clone ( ) ) , cmd . directory . clone ( ) , KeyPairType :: Account , cmd . disable_keygen , ) ? ; let subject = extract_keypair ( cmd . subject , Some ( cmd . binary . clone ( ) ) , cmd . directory , KeyPairType :: Service , cmd . disable_keygen , ) ? ; par . add_library ( & cmd . arch , & lib ) . map_err ( convert_error ) ? ; let extension = if cmd . compress { " " } else { " " } ; let outfile = match cmd . destination { Some ( path ) => path , None => format ! ( " " PathBuf from ( cmd binary clone ( ) ) file_stem ( ) unwrap ( ) to_str ( ) unwrap ( ) to_string ( ) extension ) , } ; Ok ( if par . write ( & outfile , & issuer , & subject , cmd . compress ) . is_err ( ) { format ! ( " " PathBuf from ( outfile clone ( ) ) parent ( ) unwrap ( ) ) } else { format_output ( format ! ( " " outfile ) , json ! ( { " " " " " " outfile } ) , & cmd . output . kind , ) } , ) }
Creates a provider archive using an initial architecture target, provider, and signing keys
Creates a provider archive using an initial architecture target provider and signing keys
cmd
CreateCommand