summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/credential/cargo-credential/examples/stdout-redirected.rs
blob: fb7c0446cf852f60f2853619f6f646c0d217f226 (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
25
26
27
28
//! Provider used for testing redirection of stdout.

#![allow(clippy::print_stderr)]
#![allow(clippy::print_stdout)]

use cargo_credential::{Action, Credential, CredentialResponse, Error, RegistryInfo};

struct MyCredential;

impl Credential for MyCredential {
    fn perform(
        &self,
        _registry: &RegistryInfo<'_>,
        _action: &Action<'_>,
        _args: &[&str],
    ) -> Result<CredentialResponse, Error> {
        // Informational messages should be sent on stderr.
        eprintln!("message on stderr should be sent the the parent process");

        // Reading from stdin and writing to stdout will go to the attached console (tty).
        println!("message from test credential provider");
        Err(Error::OperationNotSupported)
    }
}

fn main() {
    cargo_credential::main(MyCredential);
}