Support roc format to stdout/from stdin

This commit is contained in:
Richard Feldman 2023-10-18 23:02:38 -04:00
parent 77d2136d00
commit e442f18e68
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
3 changed files with 272 additions and 133 deletions

View file

@ -35,7 +35,7 @@ use target_lexicon::{Architecture, Triple};
use tempfile::TempDir;
mod format;
pub use format::format;
pub use format::{format_files, format_src, FormatMode};
pub const CMD_BUILD: &str = "build";
pub const CMD_RUN: &str = "run";
@ -62,6 +62,8 @@ pub const FLAG_TIME: &str = "time";
pub const FLAG_LINKER: &str = "linker";
pub const FLAG_PREBUILT: &str = "prebuilt-platform";
pub const FLAG_CHECK: &str = "check";
pub const FLAG_STDIN: &str = "stdin";
pub const FLAG_STDOUT: &str = "stdout";
pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb";
pub const ROC_FILE: &str = "ROC_FILE";
pub const ROC_DIR: &str = "ROC_DIR";
@ -258,6 +260,20 @@ pub fn build_app() -> Command {
.action(ArgAction::SetTrue)
.required(false),
)
.arg(
Arg::new(FLAG_STDIN)
.long(FLAG_STDIN)
.help("Read file to format from stdin")
.action(ArgAction::SetTrue)
.required(false),
)
.arg(
Arg::new(FLAG_STDOUT)
.long(FLAG_STDOUT)
.help("Print formatted file to stdout")
.action(ArgAction::SetTrue)
.required(false),
)
)
.subcommand(Command::new(CMD_VERSION)
.about(concatcp!("Print the Roc compilers version, which is currently ", VERSION)))
@ -342,11 +358,6 @@ pub enum BuildConfig {
BuildAndRunIfNoErrors,
}
pub enum FormatMode {
Format,
CheckOnly,
}
fn opt_level_from_flags(matches: &ArgMatches) -> OptLevel {
match (
matches.get_flag(FLAG_OPTIMIZE),