Skip to content

Commit bf41fd4

Browse files
committed
feat: alias legacy dump & legacy format
1 parent 62f2729 commit bf41fd4

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub fn build(
509509
}
510510
}
511511

512-
pub fn pass_through_legacy(args: Vec<OsString>) -> i32 {
512+
pub fn pass_through_legacy(args: &[OsString]) -> i32 {
513513
let project_root = helpers::get_abs_path(".");
514514
let workspace_root = helpers::get_workspace_root(&project_root);
515515

src/cli.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ pub enum Command {
125125
#[arg(long)]
126126
bsc_path: Option<String>,
127127
},
128+
/// Alias to `legacy format`.
129+
#[command(disable_help_flag = true)]
130+
Format {
131+
#[arg(allow_hyphen_values = true, num_args = 0..)]
132+
format_args: Vec<OsString>,
133+
},
134+
/// Alias to `legacy dump`.
135+
#[command(disable_help_flag = true)]
136+
Dump {
137+
#[arg(allow_hyphen_values = true, num_args = 0..)]
138+
dump_args: Vec<OsString>,
139+
},
128140
/// This prints the compiler arguments. It expects the path to a rescript.json file.
129141
CompilerArgs {
130142
/// Path to a rescript.json file

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn get_rescript_legacy(root_path: &str, workspace_root: Option<String>) -> S
163163
) {
164164
(Ok(path), _) => path,
165165
(_, Some(Ok(path))) => path,
166-
_ => panic!("Could not find rescript"),
166+
_ => panic!("Could not find rescript-legacy"),
167167
}
168168
.to_string_lossy()
169169
.to_string()

src/main.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22
use clap::Parser;
33
use log::LevelFilter;
44
use regex::Regex;
5-
use std::io::Write;
5+
use std::{ffi::OsString, io::Write};
66

77
use rewatch::{build, cli, cmd, lock, watcher};
88

@@ -19,12 +19,24 @@ fn main() -> Result<()> {
1919

2020
let command = args.command.unwrap_or(cli::Command::Build(args.build_args));
2121

22-
// handle legacy and compiler args early, because we don't need a lock for them
23-
match command {
22+
// handle those commands early, because we don't need a lock for them
23+
match &command {
2424
cli::Command::Legacy { legacy_args } => {
2525
let code = build::pass_through_legacy(legacy_args);
2626
std::process::exit(code);
2727
}
28+
cli::Command::Format { format_args } => {
29+
let mut args: Vec<OsString> = vec!["format".into()];
30+
args.append(&mut format_args.clone());
31+
let code = build::pass_through_legacy(args.as_slice());
32+
std::process::exit(code);
33+
}
34+
cli::Command::Dump { dump_args } => {
35+
let mut args: Vec<OsString> = vec!["dump".into()];
36+
args.append(&mut dump_args.clone());
37+
let code = build::pass_through_legacy(args.as_slice());
38+
std::process::exit(code);
39+
}
2840
cli::Command::CompilerArgs {
2941
path,
3042
dev,
@@ -33,7 +45,7 @@ fn main() -> Result<()> {
3345
} => {
3446
println!(
3547
"{}",
36-
build::get_compiler_args(&path, rescript_version, bsc_path, dev)?
48+
build::get_compiler_args(&path, rescript_version.clone(), bsc_path.clone(), *dev)?
3749
);
3850
std::process::exit(0);
3951
}
@@ -92,16 +104,12 @@ fn main() -> Result<()> {
92104

93105
Ok(())
94106
}
95-
cli::Command::CompilerArgs { .. } | cli::Command::Legacy { .. } => {
107+
cli::Command::CompilerArgs { .. }
108+
| cli::Command::Legacy { .. }
109+
| cli::Command::Format { .. }
110+
| cli::Command::Dump { .. } => {
96111
unreachable!("command already handled")
97-
} // Command::Format => {
98-
// let code = build::pass_through_legacy(vec!["format".to_owned()]);
99-
// std::process::exit(code);
100-
// }
101-
// Command::Dump => {
102-
// let code = build::pass_through_legacy(vec!["dump".to_owned()]);
103-
// std::process::exit(code);
104-
// }
112+
}
105113
},
106114
}
107115
}

0 commit comments

Comments
 (0)