summaryrefslogtreecommitdiffstats
path: root/vendor/gix-credentials/examples/custom-helper.rs
blob: 9fc0cbf61eef2840fc315055ed3c235bdf936f0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use gix_credentials::{program, protocol};

/// Run like this `echo url=https://example.com | cargo run --example custom-helper -- get`
pub fn main() -> Result<(), gix_credentials::program::main::Error> {
    gix_credentials::program::main(
        std::env::args_os().skip(1),
        std::io::stdin(),
        std::io::stdout(),
        |action, context| -> std::io::Result<_> {
            match action {
                program::main::Action::Get => Ok(Some(protocol::Context {
                    username: Some("user".into()),
                    password: Some("pass".into()),
                    ..context
                })),
                program::main::Action::Erase => Err(std::io::Error::new(
                    std::io::ErrorKind::Other,
                    "Refusing to delete credentials for demo purposes",
                )),
                program::main::Action::Store => Ok(None),
            }
        },
    )
}