Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit199cda6

Browse files
author
Alexander Weber
committed
complate 0.14 - now with lib (preliminary)
1 parent1825cf3 commit199cda6

File tree

9 files changed

+123
-139
lines changed

9 files changed

+123
-139
lines changed

‎Cargo.lock

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ categories = ["command-line-utilities"]
1212
readme ="docs/README.md"
1313
autobins =false
1414

15+
[lib]
16+
name ="complate"
17+
path ="./src/lib.rs"
18+
1519
[[bin]]
1620
name ="complate"
1721
path ="./src/main.rs"
@@ -33,12 +37,11 @@ mime = "0.3.17"
3337
serde = {version ="1.0.181",features = ["derive"] }
3438
serde_json ="1.0.104"
3539
serde_yaml ="0.9.25"
36-
thiserror ="1.0.44"
37-
anyhow ="1.0.72"
3840
dialoguer = {version ="0.10.4",optional =true }
3941
schemars ="0.8.12"
4042
fancy-regex ="0.11.0"
4143
indoc ="2.0.3"
44+
anyhow ="1.0.86"
4245

4346
[dev-dependencies]
4447
rusty-hook ="0.11.2"

‎src/args.rs

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use{
2-
crate::error::Error,
32
anyhow::Result,
43
clap::{
54
Arg,
@@ -48,30 +47,7 @@ pub enum Command {
4847
Autocomplete{path:String,shell: clap_complete::Shell},
4948
Init,
5049
Schema,
51-
Render(RenderArguments),
52-
}
53-
54-
#[derive(Debug)]
55-
pubstructRenderArguments{
56-
pubconfiguration:String,
57-
pubtemplate:Option<String>,
58-
pubvalue_overrides:HashMap<String,String>,
59-
pubshell_trust:ShellTrust,
60-
publoose:bool,
61-
pubbackend:Backend,
62-
}
63-
64-
#[derive(Debug,Eq,PartialEq)]
65-
pubenumShellTrust{
66-
None,
67-
Ultimate,
68-
}
69-
70-
#[derive(Debug)]
71-
pubenumBackend{
72-
Headless,
73-
#[cfg(feature ="backend+cli")]
74-
CLI,
50+
Render(crate::render::RenderArguments),
7551
}
7652

7753
pubstructClapArgumentLoader{}
@@ -193,7 +169,7 @@ impl ClapArgumentLoader {
193169
format:match subc.get_one::<String>("format").unwrap().as_str(){
194170
|"manpages" =>ManualFormat::Manpages,
195171
|"markdown" =>ManualFormat::Markdown,
196-
| _ =>returnErr(Error::Argument("unknown format".into()).into()),
172+
| _ =>returnErr(anyhow::anyhow!("unknown format")),
197173
},
198174
},
199175
privileges,
@@ -220,9 +196,9 @@ impl ClapArgumentLoader {
220196
let config = std::fs::read_to_string(subc.get_one::<String>("config").unwrap())?;
221197
let template = subc.get_one::<String>("template").map(|v| v.into());
222198
let shell_trust =if subc.get_flag("trust"){
223-
ShellTrust::Ultimate
199+
crate::render::ShellTrust::Ultimate
224200
}else{
225-
ShellTrust::None
201+
crate::render::ShellTrust::None
226202
};
227203
let loose = subc.get_flag("loose");
228204

@@ -234,15 +210,15 @@ impl ClapArgumentLoader {
234210
}
235211
}
236212
let backend =match subc.get_one::<String>("backend").unwrap().as_str(){
237-
|"headless" =>Backend::Headless,
213+
|"headless" =>crate::render::Backend::Headless,
238214
#[cfg(feature ="backend+cli")]
239-
|"cli" =>Backend::CLI,
240-
| _ =>returnErr(Error::Argument("no backend specified".into()).into()),
215+
|"cli" =>crate::render::Backend::CLI,
216+
| _ =>returnErr(anyhow::anyhow!("no backend specified")),
241217
};
242218

243219
Ok(CallArgs{
244220
privileges,
245-
command:Command::Render(RenderArguments{
221+
command:Command::Render(crate::render::RenderArguments{
246222
configuration: config,
247223
template,
248224
value_overrides,
@@ -252,7 +228,7 @@ impl ClapArgumentLoader {
252228
}),
253229
})
254230
}else{
255-
returnErr(Error::UnknownCommand.into());
231+
returnErr(anyhow::anyhow!("unknown command"));
256232
}
257233
}
258234
}

‎src/error.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

‎src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pubmod render;
2+
pubmod config;

‎src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ use {
44
std::path::PathBuf,
55
};
66

7-
pubmod args;
8-
pubmod config;
9-
pubmod error;
10-
pubmod reference;
11-
pubmod render;
7+
mod args;
8+
mod config;
9+
mod reference;
10+
mod render;
1211

1312
#[tokio::main]
1413
asyncfnmain() ->Result<()>{
@@ -58,15 +57,14 @@ async fn main() -> Result<()> {
5857
#[cfg(test)]
5958
mod tests{
6059
use{
61-
crate::error::Error,
6260
anyhow::Result,
6361
std::process::Command,
6462
};
6563

6664
fnexec(command:&str) ->Result<String>{
6765
let output =Command::new("sh").arg("-c").arg(command).output()?;
6866
if output.status.code().unwrap() !=0{
69-
returnErr(Error::ShellCommand(String::from_utf8(output.stderr)?).into());
67+
returnErr(anyhow::anyhow!(String::from_utf8(output.stderr)?));
7068
}
7169
Ok(String::from_utf8(output.stdout)?)
7270
}

‎src/render/cli.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use{
22
super::UserInput,
3-
crate::error::Error,
43
anyhow::Result,
54
async_trait::async_trait,
65
std::collections::{
@@ -24,11 +23,11 @@ impl<'a> UserInput for CLIBackend<'a> {
2423
asyncfnprompt(&self,text:&str) ->Result<String>{
2524
match dialoguer::Input::new().allow_empty(true).with_prompt(text).interact(){
2625
|Ok(res) =>Ok(res),
27-
|Err(_) =>Err(Error::InteractAbort.into()),
26+
|Err(_) =>Err(anyhow::anyhow!("interaction aborted")),
2827
}
2928
}
3029

31-
asyncfnselect(&self,prompt:&str,options:&BTreeMap<String,super::Option>) ->Result<String>{
30+
asyncfnselect(&self,prompt:&str,options:&BTreeMap<String,crate::config::Option>) ->Result<String>{
3231
let keys = options.keys().cloned().collect::<Vec<String>>();
3332
let display_vals = options.values().map(|x| x.display.to_owned()).collect::<Vec<String>>();
3433

@@ -43,7 +42,7 @@ impl<'a> UserInput for CLIBackend<'a> {
4342
}
4443
}
4544

46-
asyncfncheck(&self,prompt:&str,separator:&str,options:&BTreeMap<String,super::Option>) ->Result<String>{
45+
asyncfncheck(&self,prompt:&str,separator:&str,options:&BTreeMap<String,crate::config::Option>) ->Result<String>{
4746
let keys = options.keys().cloned().collect::<Vec<String>>();
4847
let display_vals = options.values().map(|x| x.display.to_owned()).collect::<Vec<String>>();
4948

‎src/render/headless.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use{
2-
super::UserInput,
3-
crate::error::Error,
42
anyhow::Result,
53
async_trait::async_trait,
64
};
@@ -14,25 +12,25 @@ impl HeadlessBackend {
1412
}
1513

1614
#[async_trait]
17-
implUserInputforHeadlessBackend{
15+
implsuper::UserInputforHeadlessBackend{
1816
asyncfnprompt(&self,_text:&str) ->Result<String>{
19-
Err(Error::Invalid("can not prompt in headless backend".into()).into())
17+
Err(anyhow::anyhow!("can not prompt in headless backend").into())
2018
}
2119

2220
asyncfnselect(
2321
&self,
2422
_prompt:&str,
25-
_options:&std::collections::BTreeMap<String,super::Option>,
23+
_options:&std::collections::BTreeMap<String,crate::config::Option>,
2624
) ->Result<String>{
27-
Err(Error::Invalid("can not prompt in headless backend".into()).into())
25+
Err(anyhow::anyhow!("can not prompt in headless backend").into())
2826
}
2927

3028
asyncfncheck(
3129
&self,
3230
_prompt:&str,
3331
_separator:&str,
34-
_options:&std::collections::BTreeMap<String,super::Option>,
32+
_options:&std::collections::BTreeMap<String,crate::config::Option>,
3533
) ->Result<String>{
36-
Err(Error::Invalid("can not prompt in headless backend".into()).into())
34+
Err(anyhow::anyhow!("can not prompt in headless backend").into())
3735
}
3836
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp