• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

johnallen3d / conditions / #58

03 Mar 2025 08:09PM UTC coverage: 33.546% (+0.3%) from 33.223%
#58

push

johnallen3d
chore(deps): bump confy from 0.5.1 to 0.6.1

Bumps [confy](https://github.com/rust-cli/confy) from 0.5.1 to 0.6.1.
- [Release notes](https://github.com/rust-cli/confy/releases)
- [Commits](https://github.com/rust-cli/confy/compare/0.5.1...v0.6.1)

---
updated-dependencies:
- dependency-name: confy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

105 of 313 relevant lines covered (33.55%)

0.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cli/src/args.rs
1
use std::fmt;
2

3
use clap::{Args, Parser, Subcommand};
4
use serde::{Deserialize, Deserializer, Serialize};
5

6
#[derive(Debug, Parser)]
7
#[clap(version, about)]
8
pub struct Conditions {
9
    #[clap(subcommand)]
10
    pub command: Command,
11
}
12

13
#[derive(Debug, Subcommand)]
14
pub enum Command {
15
    /// View configuration information
16
    Config(ConfigCommand),
17
    /// Get the current weather conditions (optional provide location)
18
    Current { region: Option<String> },
19
    /// Location conditions apply to
20
    Location(LocationCommand),
21
    /// weatherapi.com api-key
22
    WeatherApiKey(WeatherApiKeyCommand),
23
    /// Weather unit, celsius or fahrenheit
24
    Unit(UnitCommand),
25
}
26

27
#[derive(Debug, Args)]
28
pub struct ConfigCommand {
29
    #[clap(subcommand)]
30
    pub command: ConfigSubcommand,
31
}
32

33
#[derive(Debug, Subcommand)]
34
pub enum ConfigSubcommand {
35
    /// Print path to configuration file
36
    Path,
37
    /// Print all stored configuration values
38
    View,
39
}
40

41
#[derive(Debug, Args)]
42
pub struct WeatherApiKeyCommand {
43
    #[clap(subcommand)]
44
    pub command: WeatherApiKeySubcommand,
45
}
46

47
#[derive(Debug, Subcommand)]
48
pub enum WeatherApiKeySubcommand {
49
    /// Store your API key
50
    Set(SetApiKey),
51
    /// Display the current key
52
    View,
53
    /// Remove the stored key
54
    Unset,
55
}
56

57
#[derive(Debug, Args)]
58
pub struct SetApiKey {
59
    /// Your weatherapi.com key
60
    pub key: String,
61
}
62

63
#[derive(Debug, Args)]
64
pub struct LocationCommand {
65
    #[clap(subcommand)]
66
    pub command: LocationSubcommand,
67
}
68

69
#[derive(Debug, Subcommand)]
70
pub enum LocationSubcommand {
71
    /// Store your location
72
    Set(SetLocation),
73
    /// View stored location
74
    View,
75
    /// Unset current location
76
    Unset,
77
}
78

79
#[derive(Debug, Args)]
80
pub struct SetLocation {
81
    /// Postal code and country to retrieve weather for: example - 10001,usa
82
    pub region: String,
83
}
84

85
#[derive(Debug, Args)]
86
pub struct UnitCommand {
87
    #[clap(subcommand)]
88
    pub command: UnitSubcommand,
89
}
90

91
#[derive(Debug, Subcommand)]
92
pub enum UnitSubcommand {
93
    /// Store your unit
94
    Set(SetUnit),
95
    /// View stored unit
96
    View,
97
}
98

99
#[derive(Debug, Args)]
100
pub struct SetUnit {
101
    /// Temperature unit to return
102
    #[clap(value_enum)]
103
    pub unit: Unit,
104
}
105

106
#[derive(clap::ValueEnum, Clone, Copy, Debug, Default, Serialize)]
107
pub enum Unit {
108
    C,
109
    #[default]
110
    F,
111
}
112

113
impl Unit {
114
    pub fn to(self) -> conditions::Unit {
×
115
        match self {
×
116
            Unit::C => conditions::Unit::C,
×
117
            Unit::F => conditions::Unit::F,
×
118
        }
119
    }
120
}
121

122
impl fmt::Display for Unit {
123
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
×
124
        let text = match self {
×
125
            Unit::C => "celsius",
×
126
            Unit::F => "fahrenheit",
×
127
        };
128
        write!(f, "{text}")
×
129
    }
130
}
131

132
impl<'de> Deserialize<'de> for Unit {
133
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
×
134
    where
135
        D: Deserializer<'de>,
136
    {
137
        let s = String::deserialize(deserializer)?.to_lowercase();
×
138
        match s.as_str() {
×
139
            "c" => Ok(Unit::C),
×
140
            _ => Ok(Unit::F),
×
141
        }
142
    }
143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc