Skip to content

Commit b236e42

Browse files
committed
fix!:Remove cargo-deps: syntax epage#37
First pass removal of cargo-deps syntax.
1 parent e1f121a commit b236e42

File tree

8 files changed

+20
-250
lines changed

8 files changed

+20
-250
lines changed

docs/README.md

+6-44
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Under the hood, a Cargo project will be generated and built (with the Cargo outp
4949

5050
As seen from the above example, using a `fn main() {}` function is not required. If not present, the script file will be wrapped in a `fn main() { ... }` block.
5151

52-
`rust-script` will look for embedded dependency and manifest information in the script as shown by the below two equivalent `now.rs` variants:
52+
`rust-script` will look for embedded dependency and manifest information in the script as shown by the below `now.rs` variants:
5353

5454
```rust
5555
#!/usr/bin/env rust-script
@@ -66,33 +66,12 @@ fn main() {
6666
}
6767
```
6868

69-
```rust
70-
// cargo-deps: time="0.1.25"
71-
// You can also leave off the version number, in which case, it's assumed
72-
// to be "*". Also, the `cargo-deps` comment *must* be a single-line
73-
// comment, and it *must* be the first thing in the file, after the
74-
// shebang.
75-
// Multiple dependencies should be separated by commas:
76-
// cargo-deps: time="0.1.25", libc="0.2.5"
77-
fn main() {
78-
println!("{}", time::now().rfc822z());
79-
}
80-
```
81-
82-
The output from running one of the above scripts may look something like:
83-
84-
```sh
85-
$ rust-script now
86-
Wed, 28 Oct 2020 00:38:45 +0100
87-
```
88-
8969
Useful command-line arguments:
9070

9171
- `--bench`: Compile and run benchmarks. Requires a nightly toolchain.
9272
- `--debug`: Build a debug executable, not an optimised one.
9373
- `--features <features>`: Cargo features to pass when building and running.
9474
- `--force`: Force the script to be rebuilt. Useful if you want to force a recompile with a different toolchain.
95-
- `--gen-pkg-only`: Generate the Cargo package, but don't compile or run it. Effectively "unpacks" the script into a Cargo package.
9675
- `--test`: Compile and run tests.
9776

9877
## Executable Scripts
@@ -123,27 +102,7 @@ The code given is embedded into a block expression, evaluated, and printed out u
123102

124103
## Filters
125104

126-
You can use `rust-script` to write a quick filter, by specifying a closure to be called for each line read from stdin, like so:
127-
128-
```sh
129-
$ cat now.ers | rust-script --loop \
130-
"let mut n=0; move |l| {n+=1; println!(\"{:>6}: {}\",n,l.trim_right())}"
131-
1: // cargo-deps: time="0.1.25"
132-
3: fn main() {
133-
4: println!("{}", time::now().rfc822z());
134-
5: }
135-
```
136-
137-
You can achieve a similar effect to the above by using the `--count` flag, which causes the line number to be passed as a second argument to your closure:
138-
139-
```sh
140-
$ cat now.ers | rust-script --count --loop \
141-
"|l,n| println!(\"{:>6}: {}\", n, l.trim_right())"
142-
1: // cargo-deps: time="0.1.25"
143-
2: fn main() {
144-
3: println!("{}", time::now().rfc822z());
145-
4: }
146-
```
105+
TBD
147106

148107
Note that, like with expressions, you can specify a custom template for stream filters.
149108

@@ -168,7 +127,10 @@ Templates are Rust source files with two placeholders: `#{prelude}` for the auto
168127
For example, a minimal expression template that adds a dependency and imports some additional symbols might be:
169128
170129
```rust
171-
// cargo-deps: itertools="0.6.2"
130+
//! ```cargo
131+
//! [dependencies]
132+
//! itertools="0.6.2"
133+
//! ```
172134
#![allow(unused_imports)]
173135
#{prelude}
174136
use std::io::prelude::*;

src/manifest.rs

+1-149
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ use crate::Input;
1414
use log::{error, info};
1515
use std::ffi::OsString;
1616

17-
static RE_SHORT_MANIFEST: once_cell::sync::Lazy<Regex> = once_cell::sync::Lazy::new(|| {
18-
Regex::new(r"^(?i)\s*//\s*cargo-deps\s*:(.*?)(\r\n|\n)").unwrap()
19-
});
2017
static RE_MARGIN: once_cell::sync::Lazy<Regex> =
2118
once_cell::sync::Lazy::new(|| Regex::new(r"^\s*\*( |$)").unwrap());
2219
static RE_SPACE: once_cell::sync::Lazy<Regex> =
@@ -184,59 +181,6 @@ fn main() {}
184181
)
185182
);
186183

187-
assert_eq!(
188-
si!(f(r#"
189-
// Cargo-Deps: time="0.1.25"
190-
fn main() {}
191-
"#)),
192-
r!(
193-
r#"[[bin]]
194-
name = "n_input_id"
195-
path = "n.rs"
196-
197-
[dependencies]
198-
time = "0.1.25"
199-
200-
[package]
201-
authors = ["Anonymous"]
202-
edition = "2018"
203-
name = "n"
204-
version = "0.1.0"
205-
"#,
206-
r#"
207-
// Cargo-Deps: time="0.1.25"
208-
fn main() {}
209-
"#
210-
)
211-
);
212-
213-
assert_eq!(
214-
si!(f(r#"
215-
// Cargo-Deps: time="0.1.25", libc="0.2.5"
216-
fn main() {}
217-
"#)),
218-
r!(
219-
r#"[[bin]]
220-
name = "n_input_id"
221-
path = "n.rs"
222-
223-
[dependencies]
224-
libc = "0.2.5"
225-
time = "0.1.25"
226-
227-
[package]
228-
authors = ["Anonymous"]
229-
edition = "2018"
230-
name = "n"
231-
version = "0.1.0"
232-
"#,
233-
r#"
234-
// Cargo-Deps: time="0.1.25", libc="0.2.5"
235-
fn main() {}
236-
"#
237-
)
238-
);
239-
240184
assert_eq!(
241185
si!(f(r#"
242186
/*!
@@ -329,8 +273,6 @@ enum Manifest<'s> {
329273
/// The manifest is a valid TOML fragment (owned).
330274
// TODO: Change to Cow<'s, str>.
331275
TomlOwned(String),
332-
/// The manifest is a comma-delimited list of dependencies.
333-
DepList(&'s str),
334276
}
335277

336278
impl<'s> Manifest<'s> {
@@ -339,7 +281,6 @@ impl<'s> Manifest<'s> {
339281
match self {
340282
Toml(s) => toml::from_str(s),
341283
TomlOwned(ref s) => toml::from_str(s),
342-
DepList(s) => Manifest::dep_list_to_toml(s),
343284
}
344285
.map_err(|e| {
345286
MainError::Tag(
@@ -348,26 +289,6 @@ impl<'s> Manifest<'s> {
348289
)
349290
})
350291
}
351-
352-
fn dep_list_to_toml(s: &str) -> ::std::result::Result<toml::value::Table, toml::de::Error> {
353-
let mut r = String::new();
354-
r.push_str("[dependencies]\n");
355-
for dep in s.trim().split(',') {
356-
// If there's no version specified, add one.
357-
match dep.contains('=') {
358-
true => {
359-
r.push_str(dep);
360-
r.push('\n');
361-
}
362-
false => {
363-
r.push_str(dep);
364-
r.push_str("=\"*\"\n");
365-
}
366-
}
367-
}
368-
369-
toml::from_str(&r)
370-
}
371292
}
372293

373294
/**
@@ -376,7 +297,7 @@ Locates a manifest embedded in Rust source.
376297
Returns `Some((manifest, source))` if it finds a manifest, `None` otherwise.
377298
*/
378299
fn find_embedded_manifest(s: &str) -> Option<(Manifest, &str)> {
379-
find_short_comment_manifest(s).or_else(|| find_code_block_manifest(s))
300+
find_code_block_manifest(s)
380301
}
381302

382303
#[test]
@@ -433,59 +354,6 @@ fn main() {
433354
None
434355
);
435356

436-
assert_eq!(
437-
fem("// cargo-deps: time=\"0.1.25\"
438-
fn main() {}
439-
"),
440-
Some((
441-
DepList(" time=\"0.1.25\""),
442-
"// cargo-deps: time=\"0.1.25\"
443-
fn main() {}
444-
"
445-
))
446-
);
447-
448-
assert_eq!(
449-
fem("// cargo-deps: time=\"0.1.25\", libc=\"0.2.5\"
450-
fn main() {}
451-
"),
452-
Some((
453-
DepList(" time=\"0.1.25\", libc=\"0.2.5\""),
454-
"// cargo-deps: time=\"0.1.25\", libc=\"0.2.5\"
455-
fn main() {}
456-
"
457-
))
458-
);
459-
460-
assert_eq!(
461-
fem("
462-
// cargo-deps: time=\"0.1.25\" \n\
463-
fn main() {}
464-
"),
465-
Some((
466-
DepList(" time=\"0.1.25\" "),
467-
"
468-
// cargo-deps: time=\"0.1.25\" \n\
469-
fn main() {}
470-
"
471-
))
472-
);
473-
474-
assert_eq!(
475-
fem("/* cargo-deps: time=\"0.1.25\" */
476-
fn main() {}
477-
"),
478-
None
479-
);
480-
481-
assert_eq!(
482-
fem(r#"//! [dependencies]
483-
//! time = "0.1.25"
484-
fn main() {}
485-
"#),
486-
None
487-
);
488-
489357
assert_eq!(
490358
fem(r#"//! ```Cargo
491359
//! [dependencies]
@@ -584,22 +452,6 @@ fn main() {}
584452
);
585453
}
586454

587-
/**
588-
Locates a "short comment manifest" in Rust source.
589-
*/
590-
fn find_short_comment_manifest(s: &str) -> Option<(Manifest, &str)> {
591-
/*
592-
This is pretty simple: the only valid syntax for this is for the first, non-blank line to contain a single-line comment whose first token is `cargo-deps:`. That's it.
593-
*/
594-
let re = &*RE_SHORT_MANIFEST;
595-
if let Some(cap) = re.captures(s) {
596-
if let Some(m) = cap.get(1) {
597-
return Some((Manifest::DepList(m.as_str()), s));
598-
}
599-
}
600-
None
601-
}
602-
603455
/**
604456
Locates a "code block manifest" in Rust source.
605457
*/

tests/data/script-short-without-main.rs

-9
This file was deleted.

tests/data/script-short.rs

-10
This file was deleted.

tests/data/templates/boolinate.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// cargo-deps: boolinator="0.1.0"
1+
//! ```cargo
2+
//! [dependencies]
3+
//! boolinator="0.1.0"
4+
//! ```
25
36
extern crate boolinator;
47
use boolinator::Boolinator;

tests/data/templates/override/expr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// cargo-deps: boolinator="0.1.0"
1+
//! ```cargo
2+
//! [dependencies]
3+
//! boolinator="0.1.0"
4+
//! ```
25
36
extern crate boolinator;
47
use boolinator::Boolinator;

tests/data/time.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
// cargo-deps: chrono
1+
//! ```cargo
2+
//! [dependencies]
3+
//! chrono="*"
4+
//! ```
25
extern crate chrono;
36
fn main() {
47
println!("--output--");
58
println!("Hello");
6-
}
9+
}

tests/integration/script.rs

-34
Original file line numberDiff line numberDiff line change
@@ -111,40 +111,6 @@ Hello, World!
111111
fixture.close();
112112
}
113113

114-
#[test]
115-
fn test_script_short() {
116-
let fixture = crate::util::Fixture::new();
117-
fixture
118-
.cmd()
119-
.arg("tests/data/script-short.rs")
120-
.assert()
121-
.success()
122-
.stdout_eq(
123-
"--output--
124-
Some(1)
125-
",
126-
);
127-
128-
fixture.close();
129-
}
130-
131-
#[test]
132-
fn test_script_short_without_main() {
133-
let fixture = crate::util::Fixture::new();
134-
fixture
135-
.cmd()
136-
.arg("tests/data/script-short-without-main.rs")
137-
.assert()
138-
.success()
139-
.stdout_eq(
140-
"--output--
141-
Some(1)
142-
",
143-
);
144-
145-
fixture.close();
146-
}
147-
148114
#[test]
149115
fn test_script_test() {
150116
let fixture = crate::util::Fixture::new();

0 commit comments

Comments
 (0)