Skip to content

Commit 59ba344

Browse files
committed
functora-cfg ReClap and IdClap
1 parent 0726be8 commit 59ba344

File tree

3 files changed

+101
-9
lines changed

3 files changed

+101
-9
lines changed

rust/flake.lock

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/flake.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33

44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-25.05";
6+
unstable.url = "github:nixos/nixpkgs?ref=nixos-unstable";
67
rust-overlay.url = "github:oxalica/rust-overlay";
78
flake-utils.url = "github:numtide/flake-utils";
89
};
910

1011
outputs = {
1112
self,
1213
nixpkgs,
14+
unstable,
1315
rust-overlay,
1416
flake-utils,
1517
}:
1618
flake-utils.lib.eachDefaultSystem (
1719
system: let
18-
pkgs = nixpkgs.legacyPackages.${system};
20+
pkgs = unstable.legacyPackages.${system};
1921
mkRustPkg = pkg:
2022
pkgs.rustPlatform.buildRustPackage {
2123
name = pkg;

rust/functora-cfg/src/lib.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clap::{Args, FromArgMatches, Subcommand};
33
pub use config::ConfigError;
44
use config::{Config, Environment, File, Value};
55
use serde::{Deserialize, Serialize, de::DeserializeOwned};
6-
use std::path::Path;
6+
use std::{collections::HashMap, path::Path};
77
use toml::Value as TomlValue;
88

99
pub struct Cfg<'a, Src: Serialize> {
@@ -121,6 +121,31 @@ where
121121
pub next: Option<Box<U>>,
122122
}
123123

124+
impl<T, U> ReClap<T, U>
125+
where
126+
T: Args,
127+
U: Subcommand,
128+
{
129+
pub fn vec(self, f: fn(U) -> ReClap<T, U>) -> Vec<T> {
130+
let mut prev = vec![self.prev];
131+
if let Some(next) = self.next {
132+
prev.extend(f(*next).vec(f))
133+
}
134+
prev
135+
}
136+
137+
pub fn hash_map(
138+
self,
139+
f: fn(U) -> ReClap<T, U>,
140+
) -> HashMap<String, T> {
141+
self.vec(f)
142+
.into_iter()
143+
.enumerate()
144+
.map(|(k, v)| (k.to_string(), v))
145+
.collect()
146+
}
147+
}
148+
124149
impl<T, U> Args for ReClap<T, U>
125150
where
126151
T: Args,
@@ -168,3 +193,51 @@ where
168193
unimplemented!()
169194
}
170195
}
196+
197+
#[derive(
198+
Eq,
199+
PartialEq,
200+
Ord,
201+
PartialOrd,
202+
Debug,
203+
Clone,
204+
Serialize,
205+
Deserialize,
206+
)]
207+
pub struct IdClap<T>(T);
208+
209+
impl<T> IdClap<T> {
210+
pub fn run(IdClap(x): Self) -> T {
211+
x
212+
}
213+
}
214+
215+
impl<T> FromArgMatches for IdClap<T> {
216+
fn from_arg_matches(
217+
_: &clap::ArgMatches,
218+
) -> Result<Self, clap::Error> {
219+
unimplemented!()
220+
}
221+
fn update_from_arg_matches(
222+
&mut self,
223+
_: &clap::ArgMatches,
224+
) -> Result<(), clap::Error> {
225+
unimplemented!()
226+
}
227+
}
228+
229+
impl<T> Subcommand for IdClap<T> {
230+
fn augment_subcommands(
231+
_: clap::Command,
232+
) -> clap::Command {
233+
unimplemented!()
234+
}
235+
fn augment_subcommands_for_update(
236+
_: clap::Command,
237+
) -> clap::Command {
238+
unimplemented!()
239+
}
240+
fn has_subcommand(_: &str) -> bool {
241+
unimplemented!()
242+
}
243+
}

0 commit comments

Comments
 (0)