forked from tauri-apps/cargo-mobile2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopts.rs
121 lines (105 loc) · 2.58 KB
/
opts.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
use serde::{Deserialize, Serialize};
#[cfg(feature = "cli")]
use structopt::clap::arg_enum;
#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub enum NoiseLevel {
Polite,
LoudAndProud,
FranklyQuitePedantic,
}
impl Default for NoiseLevel {
fn default() -> Self {
Self::Polite
}
}
impl NoiseLevel {
pub fn from_occurrences(occurrences: u64) -> Self {
match occurrences {
0 => Self::Polite,
1 => Self::LoudAndProud,
_ => Self::FranklyQuitePedantic,
}
}
pub fn polite(self) -> bool {
matches!(self, Self::Polite)
}
pub fn loud(self) -> bool {
matches!(self, Self::LoudAndProud)
}
pub fn pedantic(self) -> bool {
matches!(self, Self::FranklyQuitePedantic)
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum Profile {
Debug,
Release,
}
impl Profile {
pub fn from_flag(flag: bool) -> Self {
if flag {
Self::Release
} else {
Self::Debug
}
}
pub fn debug(self) -> bool {
matches!(self, Self::Debug)
}
pub fn release(self) -> bool {
matches!(self, Self::Release)
}
pub fn as_str(&self) -> &'static str {
match self {
Self::Debug => "debug",
Self::Release => "release",
}
}
pub fn as_str_pascal_case(&self) -> &'static str {
match self {
Self::Debug => "Debug",
Self::Release => "Release",
}
}
pub fn suffix(&self) -> &str {
match self {
Profile::Debug => self.as_str(),
// TODO: how to handle signed APKs?
Profile::Release => "release-unsigned",
}
}
}
/// Android device logging filter level, used as an argument for run
#[cfg(not(feature = "cli"))]
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum FilterLevel {
Error,
Warn,
Info,
Debug,
Verbose,
}
#[cfg(feature = "cli")]
arg_enum! {
/// Android device logging filter level, used as an argument for run
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum FilterLevel {
Error,
Warn,
Info,
Debug,
Verbose,
}
}
impl FilterLevel {
/// Filter level for logcat
pub fn logcat(&self) -> &'static str {
match self {
Self::Error => "E",
Self::Warn => "W",
Self::Info => "I",
Self::Debug => "D",
Self::Verbose => "V",
}
}
}