polyhorn_cli/
lib.rs

1//! CLI that makes it easy to work with Polyhorn projects. Specifically, the CLI
2//! takes care of building, running and distributing cross-platform apps written
3//! with Polyhorn.
4
5#![warn(missing_docs)]
6
7pub mod android;
8pub mod commands;
9pub mod core;
10pub mod ios;
11pub mod spec;
12pub mod template;
13pub mod test;
14
15use clap::{AppSettings, Clap};
16use std::path::PathBuf;
17
18/// Contains a configuration that is passed to the implementation of each
19/// (relevant) CLI command. A notable exception is `polyhorn new`, which doesn't
20/// require a pre-existing `Polyhorn.toml` manifest file.
21#[derive(Debug)]
22pub struct Config {
23    /// Contains the path of the directory that stores the `Polyhorn.toml` file.
24    pub manifest_dir: PathBuf,
25
26    /// Contains the path of the `Polyhorn.toml` file itself.
27    pub manifest_path: PathBuf,
28
29    /// Contains the path of the directory that build products should be written
30    /// to.
31    pub target_dir: PathBuf,
32
33    /// Contains the specification that is read from the `Polyhorn.toml` file.
34    pub spec: spec::Spec,
35}
36
37/// Polyhorn is a platform for rapidly building apps that run everywhere.
38#[derive(Clap)]
39#[clap(name = "polyhorn", version = env!("CARGO_PKG_VERSION"), author = "Glacyr B.V.")]
40#[clap(setting(AppSettings::ColoredHelp))]
41struct Opts {
42    #[clap(subcommand)]
43    subcmd: SubCommand,
44
45    #[clap(long = "manifest-path", default_value = "Polyhorn.toml")]
46    manifest_path: PathBuf,
47}
48
49/// Subcommands provided by the Polyhorn CLI.
50#[derive(Clap)]
51enum SubCommand {
52    /// Creates a new Polyhorn app in the given directory.
53    Init(commands::Init),
54
55    /// Runs the app on a device or simulator.
56    Run(commands::Run),
57
58    /// Tests the app on a device or simulator.
59    Test(commands::Test),
60}
61
62/// Entry point of the CLI that is used by the main `polyhorn` package. The
63/// `polyhorn-cli` package itself doesn't provide a binary. This is because we
64/// want to ship a library named `polyhorn` and a CLI with the same name (but
65/// different crates obviously can't share the same name). So instead, the
66/// library gets to be `polyhorn` and comes with a binary target that simply
67/// calls `polyhorn_cli::cli()`.
68pub fn cli() {
69    #[cfg(windows)]
70    let _enabled = ansi_term::enable_ansi_support();
71
72    let opts = Opts::parse();
73
74    match opts.subcmd {
75        SubCommand::Init(init) => init.main(),
76        SubCommand::Run(run) => run.main(&opts.manifest_path),
77        SubCommand::Test(test) => test.main(&opts.manifest_path),
78    }
79}