This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
/
cli.rs
141 lines (120 loc) · 4.48 KB
/
cli.rs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Defines the CLI interface using structopt.
use std::path::PathBuf;
#[derive(StructOpt, Debug)]
#[structopt(name = "lorri")]
/// Global arguments which set global program state. Most
/// arguments will be to sub-commands.
pub struct Arguments {
/// Activate debug logging. Multiple occurrences are accepted for backwards compatibility, but
/// have no effect.
#[structopt(short = "v", long = "verbose", parse(from_occurrences))]
pub verbosity: u8,
/// Sub-command to execute
#[structopt(subcommand)]
pub command: Command,
}
#[derive(StructOpt, Debug)]
/// Sub-commands which Lorri can execute
pub enum Command {
/// Emit shell script intended to be evaluated as part of
/// direnv's .envrc, via: `eval "$(lorri direnv)"`
#[structopt(name = "direnv")]
Direnv(DirenvOptions),
/// Show information about the current Lorri project
#[structopt(name = "info", alias = "information")]
Info(InfoOptions),
/// Open a new shell
#[structopt(name = "shell")]
Shell(ShellOptions),
/// Build `shell.nix` whenever an input file changes
#[structopt(name = "watch")]
Watch(WatchOptions),
/// Start the multi-project daemon. Replaces `lorri watch`
#[structopt(name = "daemon")]
Daemon,
/// (plumbing) Tell the lorri daemon to care about the current directory's project
#[structopt(name = "ping_")]
Ping_(Ping_),
/// Upgrade Lorri
#[structopt(name = "self-upgrade", alias = "self-update")]
Upgrade(UpgradeTo),
/// Bootstrap files for a new setup
#[structopt(name = "init")]
Init,
}
/// Options for the `direnv` subcommand.
#[derive(StructOpt, Debug)]
pub struct DirenvOptions {
/// The .nix file in the current directory to use
#[structopt(long = "shell-file", parse(from_os_str), default_value = "shell.nix")]
pub nix_file: PathBuf,
}
/// Options for the `info` subcommand.
#[derive(StructOpt, Debug)]
pub struct InfoOptions {
/// The .nix file in the current directory to use
// The "shell-file" argument has no default value. That's on purpose: sometimes users have
// projects with multiple shell files. This way, they are forced to think about which shell
// file was causing problems when they submit a bug report.
#[structopt(long = "shell-file", parse(from_os_str))]
pub nix_file: PathBuf,
}
/// Options for the `shell` subcommand.
#[derive(StructOpt, Debug)]
pub struct ShellOptions {
/// The .nix file in the current directory to use
#[structopt(long = "shell-file", parse(from_os_str), default_value = "shell.nix")]
pub nix_file: PathBuf,
}
/// Options for the `watch` subcommand.
#[derive(StructOpt, Debug)]
pub struct WatchOptions {
/// The .nix file in the current directory to use
#[structopt(long = "shell-file", parse(from_os_str), default_value = "shell.nix")]
pub nix_file: PathBuf,
/// Exit after a the first build
#[structopt(long = "once")]
pub once: bool,
}
/// Send a message with a lorri project.
///
/// Pinging with a project tells the daemon that the project was recently interacted with.
/// If the daemon has not been pinged for a project, it begins listening. If it does not
/// get pinged for a long time, it may stop watching the project for changes.
#[derive(StructOpt, Debug)]
pub struct Ping_ {
/// The .nix file to watch and build on changes.
#[structopt(parse(from_os_str))]
pub nix_file: PathBuf,
}
/// A stub struct to represent how what we want to upgrade to.
#[derive(StructOpt, Debug)]
#[structopt(name = "basic")]
pub struct UpgradeTo {
/// the path to a local check out of Lorri.
#[structopt(subcommand)]
pub source: Option<UpgradeSource>,
}
/// Version-specifiers of different upgrade targets.
#[derive(StructOpt, Debug)]
pub enum UpgradeSource {
/// Upgrade to the current rolling-release version, will be
/// fetched from git and built locally. rolling-release is
/// expected to be more stable than master. (default)
#[structopt(name = "rolling-release")]
RollingRelease,
/// Upgrade to the current version from the master branch, which
/// will be fetched from git and built locally.
#[structopt(name = "master")]
Master,
/// Upgrade to a version in an arbitrary local directory.
#[structopt(name = "local")]
Local(LocalDest),
}
/// Install an arbitrary version of Lorri from a local directory.
#[derive(StructOpt, Debug)]
pub struct LocalDest {
/// the path to a local check out of Lorri.
#[structopt(parse(from_os_str))]
pub path: PathBuf,
}