Skip to content

Commit d3a7a35

Browse files
committed
feat(token): allow using -H/--header to get an HTTPie header argument
1 parent 007acb1 commit d3a7a35

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/cmd/token.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ pub struct GetToken {
3333
#[arg(short, long)]
3434
pub bearer: bool,
3535

36+
/// Suitable for using directly with HTTPie as header
37+
#[arg(short = 'H', long, conflicts_with = "bearer")]
38+
pub header: bool,
39+
3640
/// Inspect the token
3741
#[arg(short = 'I', long, conflicts_with = "bearer")]
3842
pub inspect: bool,
@@ -84,12 +88,19 @@ impl GetToken {
8488
token.access_token
8589
};
8690

87-
if self.bearer {
88-
println!("Bearer {token}");
89-
} else if self.inspect {
90-
inspect(token)?;
91-
} else {
92-
println!("{token}");
91+
match (self.bearer, self.header, self.inspect) {
92+
(true, _, _) => {
93+
println!("Bearer {token}");
94+
}
95+
(_, true, _) => {
96+
println!("Authorization:Bearer {token}");
97+
}
98+
(_, _, true) => {
99+
inspect(token)?;
100+
}
101+
_ => {
102+
println!("{token}");
103+
}
93104
}
94105

95106
Ok(())

0 commit comments

Comments
 (0)