Skip to content

Commit 2db3739

Browse files
authored
Merge pull request #81 from fornwall/print-path-to-package
Make --gen-pkg-only print path to package
2 parents 54a2768 + ae12c10 commit 2db3739

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ Wed, 28 Oct 2020 00:38:45 +0100
9898

9999
Useful command-line arguments:
100100

101-
- `--bench`: Compile and run benchmarks. Requires a nightly toolchain.
101+
- `--bench`: Compile and run benchmarks. Requires a nightly toolchain.
102102
- `--debug`: Build a debug executable, not an optimised one.
103103
- `--force`: Force the script to be rebuilt. Useful if you want to force a recompile with a different toolchain.
104-
- `--gen-pkg-only`: Generate the Cargo package, but don't compile or run it. Effectively "unpacks" the script into a Cargo package.
104+
- `--project`: Generate the Cargo package and print the path to it - but don't compile or run it. Effectively "unpacks" the script into a Cargo package.
105105
- `--test`: Compile and run tests.
106106

107107
## Executable Scripts

src/arguments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Args {
134134
)
135135
.arg(Arg::new("gen_pkg_only")
136136
.help("Generate the Cargo package, but don't compile or run it.")
137-
.long("gen-pkg-only")
137+
.long("project")
138138
.action(ArgAction::SetTrue)
139139
.requires("script")
140140
.conflicts_with_all(["debug", "force", "test", "bench"])

src/main.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,21 @@ fn try_main() -> MainResult<i32> {
179179
})
180180
};
181181

182+
if !action.execute {
183+
println!("{}", action.pkg_path.display());
184+
return Ok(0);
185+
}
186+
182187
#[cfg(unix)]
183188
{
184-
if action.execute {
185-
let mut cmd = action.cargo(&args.script_args)?;
186-
187-
let err = cmd.exec();
188-
Err(MainError::from(err))
189-
} else {
190-
Ok(0)
191-
}
189+
let mut cmd = action.cargo(&args.script_args)?;
190+
let err = cmd.exec();
191+
Err(MainError::from(err))
192192
}
193193
#[cfg(not(unix))]
194194
{
195-
let exit_code = if action.execute {
196-
let mut cmd = action.cargo(&args.script_args)?;
197-
198-
cmd.status().map(|st| st.code().unwrap_or(1))?
199-
} else {
200-
0
201-
};
195+
let mut cmd = action.cargo(&args.script_args)?;
196+
let exit_code = cmd.status().map(|st| st.code().unwrap_or(1))?;
202197
Ok(exit_code)
203198
}
204199
}

tests/scripts/gen-only.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
About to cargo run
2+
hello, world

tests/scripts/gen-only.script

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
set -e -u
3+
4+
# https://unix.stackexchange.com/questions/30091/fix-or-alternative-for-mktemp-in-os-x
5+
mytmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
6+
7+
cd "$mytmpdir"
8+
9+
printf 'println!("hello, world");' > script.rs
10+
11+
cd $(rust-script --project script.rs)
12+
13+
echo "About to cargo run"
14+
cargo run -q

0 commit comments

Comments
 (0)