1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crateAsCommand;
use Path;
use Command;
/// Runs a system command.
///
/// # Arguments
///
/// * `cmd` - The command to run. The command can be represented as a single string or a collection
/// of strings, or as any other type that implements the [`crate::AsCommand`] trait.
/// * `dir` - Path to the directory that the command specified by `cmd` should be run in (can be a
/// `&str`, [`String`], [`Path`], or [`std::path::PathBuf`].). If [`None`], the command is run in
/// the current working directory.
///
/// # Returns
///
/// A result where:
///
/// * `Ok` contains `()` if the command executes successfully (exit status zero).
/// * `Err` contains an error message if the command fails to run or exits with a non-zero status.
///
/// # Example
///
/// ```
/// use easy_cmd::run_command;
/// use std::path::Path;
///
/// // Run `git status` inside the current working directory (the `easy_cmd` repo).
/// // --> Note: we have to disambiguate the `None` type to `None::<&str>` since the compiler
/// // cannot infer the type of the path.
/// run_command("git status", None::<&str>).unwrap();
///
/// // Alternatively, we could run the same command using a collection of strings.
/// // --> Note: like before, we have to disambiguate the `None` type to `None::<&str>` since the
/// // compile cannot infer the type of the path.
/// run_command(&["git", "status"], None::<&str>).unwrap();
///
/// // If we want to run `ls -la` in the `src` directory, we can do it like this:
/// run_command("ls -la", Some("src")).unwrap();
///
/// // Alternatively, we could run the same command using a a collection of strings for the command
/// // and a `Path` for the directory:
/// run_command(&vec!["ls", "-la"], Some(Path::new("src"))).unwrap();
/// ```
Sized, P: >