History

First sketch of git-command API (#450)

Sebastian Thiel committed 4 years ago

Commit cd4a6081 parent 6c27e944 files · +58 −0Browse files

Showing the changes to git-command (3 of 4 files). Show all

Unified · Split

3 files
  1. git-command/Cargo.toml +1 −0
  2. git-command/src/lib.rs +34 −0
  3. git-command/tests/command.rs +20 −0
git-command/Cargo.toml+1−0
@@ -11,3 +11,4 @@ edition = "2018" · 10 unmodified lines
11doctest = false11doctest = false
12 12
13[dependencies]13[dependencies]
14git-testtools = { path = "../tests/tools" }
git-command/src/lib.rs+34−0
@@ -1,2 +1,36 @@
1#![deny(rust_2018_idioms)]1#![deny(rust_2018_idioms)]
2#![forbid(unsafe_code)]2#![forbid(unsafe_code)]
3#![allow(dead_code)]
4
5use std::ffi::OsString;
6
7pub struct Prepare {
8 command: OsString,
9 use_shell: bool,
10}
11
12mod prepare {
13 use crate::Prepare;
14
15 /// Builder
16 impl Prepare {
17 pub fn with_shell(mut self) -> Self {
18 self.use_shell = true;
19 self
20 }
21 }
22
23 /// Finalization
24 impl Prepare {
25 pub fn spawn(self) -> std::io::Result<std::process::Child> {
26 todo!("create command and spawn that")
27 }
28 }
29}
30
31pub fn prepare(cmd: impl Into<OsString>) -> Prepare {
32 Prepare {
33 command: cmd.into(),
34 use_shell: false,
35 }
36}
git-command/tests/command.rs+20−0
@@ -0,0 +1,20 @@
1mod spawn {
2 #[test]
3 #[ignore]
4 fn direct_command_execution_searches_in_path() {
5 git_command::prepare(if cfg!(unix) { "ls" } else { "dir.exe" })
6 .spawn()
7 .unwrap();
8 }
9
10 mod with_shell {
11 #[test]
12 #[ignore]
13 fn command_in_path_with_args() {
14 git_command::prepare(if cfg!(unix) { "ls -l" } else { "dir.exe -a" })
15 .with_shell()
16 .spawn()
17 .unwrap();
18 }
19 }
20}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t