stillwright 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stillwright-0.2.0 → stillwright-0.2.1}/Cargo.lock +1 -1
- {stillwright-0.2.0 → stillwright-0.2.1}/Cargo.toml +1 -1
- {stillwright-0.2.0 → stillwright-0.2.1}/PKG-INFO +2 -3
- {stillwright-0.2.0 → stillwright-0.2.1}/README.md +1 -2
- {stillwright-0.2.0 → stillwright-0.2.1}/src/gate.rs +105 -15
- {stillwright-0.2.0 → stillwright-0.2.1}/LICENSE +0 -0
- {stillwright-0.2.0 → stillwright-0.2.1}/examples/quickstart-run/README.md +0 -0
- {stillwright-0.2.0 → stillwright-0.2.1}/press/README.md +0 -0
- {stillwright-0.2.0 → stillwright-0.2.1}/pyproject.toml +0 -0
- {stillwright-0.2.0 → stillwright-0.2.1}/src/main.rs +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stillwright
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Classifier: Environment :: Console
|
|
5
5
|
Classifier: Programming Language :: Rust
|
|
6
6
|
Classifier: Topic :: Software Development
|
|
@@ -192,8 +192,7 @@ Cost is measured, not assumed: the harness, the price table and the cache linter
|
|
|
192
192
|
|
|
193
193
|
## Who runs it
|
|
194
194
|
|
|
195
|
-
One person, [Hamza Ilyas](https://github.com/HamzaIlyas)
|
|
196
|
-
[Folvix](https://huggingface.co/Folvix). Questions and ideas:
|
|
195
|
+
One person, [Hamza Ilyas](https://github.com/HamzaIlyas). Questions and ideas:
|
|
197
196
|
[Discussions](https://github.com/HamzaIlyas/stillwright/discussions). Bugs:
|
|
198
197
|
[issues](https://github.com/HamzaIlyas/stillwright/issues/new?template=idea.yml), read daily.
|
|
199
198
|
|
|
@@ -175,8 +175,7 @@ Cost is measured, not assumed: the harness, the price table and the cache linter
|
|
|
175
175
|
|
|
176
176
|
## Who runs it
|
|
177
177
|
|
|
178
|
-
One person, [Hamza Ilyas](https://github.com/HamzaIlyas)
|
|
179
|
-
[Folvix](https://huggingface.co/Folvix). Questions and ideas:
|
|
178
|
+
One person, [Hamza Ilyas](https://github.com/HamzaIlyas). Questions and ideas:
|
|
180
179
|
[Discussions](https://github.com/HamzaIlyas/stillwright/discussions). Bugs:
|
|
181
180
|
[issues](https://github.com/HamzaIlyas/stillwright/issues/new?template=idea.yml), read daily.
|
|
182
181
|
|
|
@@ -134,17 +134,92 @@ fn raise(decision: &mut Decision, verdict: Verdict, reason: String) {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
/// A word under construction: its text, and where quoting (quotes or a backslash) first
|
|
138
|
+
/// began in it, if anywhere. A quoted `">"` is a file name; only a bare operator is a
|
|
139
|
+
/// redirection, and `2>'/dev/null'` is one because its operator comes before the quote.
|
|
140
|
+
#[derive(Default)]
|
|
141
|
+
struct Word {
|
|
142
|
+
text: String,
|
|
143
|
+
quoted_from: Option<usize>,
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
impl Word {
|
|
147
|
+
fn mark_quoted(&mut self) {
|
|
148
|
+
self.quoted_from.get_or_insert(self.text.len());
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fn bare(&self) -> bool {
|
|
152
|
+
self.quoted_from.is_none()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// The redirection this word is, if its operator is unquoted.
|
|
156
|
+
fn redirection(&self) -> Option<bool> {
|
|
157
|
+
let (op_end, takes_operand) = redirection(&self.text)?;
|
|
158
|
+
match self.quoted_from {
|
|
159
|
+
Some(from) if from < op_end => None,
|
|
160
|
+
_ => Some(takes_operand),
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fn flush_word(word: &mut Word, words: &mut Vec<Word>) {
|
|
166
|
+
if !word.text.is_empty() {
|
|
139
167
|
words.push(std::mem::take(word));
|
|
168
|
+
} else {
|
|
169
|
+
word.quoted_from = None;
|
|
140
170
|
}
|
|
141
171
|
}
|
|
142
172
|
|
|
143
|
-
fn flush_cmd(word: &mut
|
|
173
|
+
fn flush_cmd(word: &mut Word, words: &mut Vec<Word>, commands: &mut Vec<Vec<String>>) {
|
|
144
174
|
flush_word(word, words);
|
|
175
|
+
let words = strip_redirections(std::mem::take(words));
|
|
145
176
|
if !words.is_empty() {
|
|
146
|
-
commands.push(
|
|
177
|
+
commands.push(words);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/// What a word means as a shell redirection: `None` for an ordinary word, else the byte
|
|
182
|
+
/// length of the operator (digits, `&` and the arrows) and whether its operand is the next
|
|
183
|
+
/// word: true for a bare operator (`>`, `2>`, `>>`, `&>`, `<`), false for one complete by
|
|
184
|
+
/// itself (`>/dev/null`, `2>&1`, `>&2`, `2>>log`). `<(` is process substitution, not a
|
|
185
|
+
/// redirection, and stays a word so `bash <(curl …)` is still seen.
|
|
186
|
+
fn redirection(word: &str) -> Option<(usize, bool)> {
|
|
187
|
+
let s = word.trim_start_matches(|c: char| c.is_ascii_digit());
|
|
188
|
+
let s = s.strip_prefix('&').unwrap_or(s);
|
|
189
|
+
let op = ["<<<", ">>", "<<", ">&", "<&", ">|", "<>", ">", "<"]
|
|
190
|
+
.iter()
|
|
191
|
+
.find(|op| s.starts_with(*op))?;
|
|
192
|
+
let rest = &s[op.len()..];
|
|
193
|
+
if rest.starts_with('(') {
|
|
194
|
+
return None;
|
|
195
|
+
}
|
|
196
|
+
Some((word.len() - rest.len(), rest.is_empty()))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/// True for text that a following `>` or `<` continues rather than ends: nothing, digits,
|
|
200
|
+
/// `&`, or an operator already begun (`>` before the second `>` of `>>`).
|
|
201
|
+
fn redirection_prefix(text: &str) -> bool {
|
|
202
|
+
let rest = text.trim_start_matches(|c: char| c.is_ascii_digit());
|
|
203
|
+
rest.is_empty() || rest == "&" || redirection(rest).is_some()
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/// Drop redirections and their operands: `rm -f x > /dev/null` removes `x`, not `/dev/null`
|
|
207
|
+
/// (issue #10). A redirection names where output goes, never what the command acts on.
|
|
208
|
+
/// A quoted or escaped operator (`rm -rf ">" ~`) is an argument and is kept.
|
|
209
|
+
fn strip_redirections(words: Vec<Word>) -> Vec<String> {
|
|
210
|
+
let mut kept = Vec::with_capacity(words.len());
|
|
211
|
+
let mut operand_next = false;
|
|
212
|
+
for word in words {
|
|
213
|
+
if operand_next {
|
|
214
|
+
operand_next = false;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
match word.redirection() {
|
|
218
|
+
Some(takes_operand) => operand_next = takes_operand,
|
|
219
|
+
None => kept.push(word.text),
|
|
220
|
+
}
|
|
147
221
|
}
|
|
222
|
+
kept
|
|
148
223
|
}
|
|
149
224
|
|
|
150
225
|
/// Split a command line into simple commands, honouring quotes. Separators: `;`, `&&`,
|
|
@@ -152,8 +227,8 @@ fn flush_cmd(word: &mut String, words: &mut Vec<String>, commands: &mut Vec<Vec<
|
|
|
152
227
|
/// so a command inside a subshell, a loop body or a substitution is still seen.
|
|
153
228
|
fn split_commands(line: &str) -> Vec<Vec<String>> {
|
|
154
229
|
let mut commands = Vec::new();
|
|
155
|
-
let mut words: Vec<
|
|
156
|
-
let mut word =
|
|
230
|
+
let mut words: Vec<Word> = Vec::new();
|
|
231
|
+
let mut word = Word::default();
|
|
157
232
|
let mut quote: Option<char> = None;
|
|
158
233
|
let mut chars = line.chars().peekable();
|
|
159
234
|
while let Some(c) = chars.next() {
|
|
@@ -166,34 +241,49 @@ fn split_commands(line: &str) -> Vec<Vec<String>> {
|
|
|
166
241
|
chars.next();
|
|
167
242
|
flush_cmd(&mut word, &mut words, &mut commands);
|
|
168
243
|
} else {
|
|
169
|
-
word.push(c);
|
|
244
|
+
word.text.push(c);
|
|
170
245
|
}
|
|
171
246
|
}
|
|
172
247
|
None => match c {
|
|
173
|
-
'\'' | '"' =>
|
|
248
|
+
'\'' | '"' => {
|
|
249
|
+
quote = Some(c);
|
|
250
|
+
word.mark_quoted();
|
|
251
|
+
}
|
|
174
252
|
// A backslash escapes in POSIX shells; on Windows it separates path parts.
|
|
175
253
|
'\\' if !cfg!(windows) => {
|
|
176
254
|
if let Some(next) = chars.next() {
|
|
177
|
-
word.
|
|
255
|
+
word.mark_quoted();
|
|
256
|
+
word.text.push(next);
|
|
178
257
|
}
|
|
179
258
|
}
|
|
180
259
|
' ' | '\t' => flush_word(&mut word, &mut words),
|
|
260
|
+
// `build>/dev/null`: a bare `>` or `<` after a word starts the redirection.
|
|
261
|
+
'>' | '<' if !word.text.is_empty() && !redirection_prefix(&word.text) => {
|
|
262
|
+
flush_word(&mut word, &mut words);
|
|
263
|
+
word.text.push(c);
|
|
264
|
+
}
|
|
265
|
+
// `2>&1`, `>&2`, `&>file`: the `&` belongs to the redirection, not a separator.
|
|
266
|
+
'&' if word.bare() && word.redirection() == Some(true) => word.text.push(c),
|
|
267
|
+
'&' if word.text.is_empty() && chars.peek() == Some(&'>') => word.text.push(c),
|
|
181
268
|
';' | '\n' | '|' | '&' | '(' | ')' | '{' | '}' | '`' => {
|
|
182
269
|
if (c == '|' || c == '&') && chars.peek() == Some(&c) {
|
|
183
270
|
chars.next();
|
|
184
271
|
}
|
|
185
|
-
if c == '(' && word == "$" {
|
|
186
|
-
word.clear();
|
|
272
|
+
if c == '(' && word.text == "$" {
|
|
273
|
+
word.text.clear();
|
|
187
274
|
}
|
|
188
|
-
if c == '(' && word == "<" {
|
|
275
|
+
if c == '(' && word.text == "<" && word.bare() {
|
|
189
276
|
// bash <(curl …): process substitution feeding a shell
|
|
190
|
-
word.clear();
|
|
191
|
-
words.push(
|
|
277
|
+
word.text.clear();
|
|
278
|
+
words.push(Word {
|
|
279
|
+
text: "<(".into(),
|
|
280
|
+
quoted_from: None,
|
|
281
|
+
});
|
|
192
282
|
continue;
|
|
193
283
|
}
|
|
194
284
|
flush_cmd(&mut word, &mut words, &mut commands);
|
|
195
285
|
}
|
|
196
|
-
_ => word.push(c),
|
|
286
|
+
_ => word.text.push(c),
|
|
197
287
|
},
|
|
198
288
|
}
|
|
199
289
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|