Skip to main content

libwally/commands/
package.rs

1use std::path::PathBuf;
2
3use structopt::StructOpt;
4
5use crate::package_contents::PackageContents;
6
7/// Package the project as a tarball suitable for uploading to a package
8/// registry.
9#[derive(Debug, StructOpt)]
10pub struct PackageSubcommand {
11    /// Path to the project to turn into a package ready for upload to an index
12    #[structopt(long = "project-path", default_value = ".")]
13    pub project_path: PathBuf,
14
15    /// Output a list of files which would be included in the package instead
16    /// of creating the package
17    #[structopt(short, long)]
18    pub list: bool,
19
20    /// Output file path where the package will be created
21    #[structopt(long = "output", required_unless("list"))]
22    pub output_path: Option<PathBuf>,
23}
24
25impl PackageSubcommand {
26    pub fn run(self) -> anyhow::Result<()> {
27        if self.list {
28            let contents_list = PackageContents::filtered_contents(&self.project_path)?;
29
30            for path in contents_list {
31                println!("{}", path.display());
32            }
33        } else {
34            let contents = PackageContents::pack_from_path(&self.project_path)?;
35            fs_err::write(&self.output_path.unwrap(), contents.data())?;
36        }
37
38        Ok(())
39    }
40}