Skip to content

Commit 2c61468

Browse files
authored
feat: add --output option (#43)
1 parent 9618710 commit 2c61468

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Diff for: src/args.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use clap::Parser;
22

33
use crate::github_repo::GitHubRepo;
44

5+
pub const STDIN: &str = "-";
6+
57
#[derive(Debug, Parser)]
68
#[command(author, version, about, long_about = None)]
79
pub struct Args {
@@ -19,4 +21,7 @@ pub struct Args {
1921

2022
#[arg(long, value_delimiter = ',')]
2123
pub repos: Vec<GitHubRepo>,
24+
25+
#[arg(long, short, default_value = STDIN)]
26+
pub output: String,
2227
}

Diff for: src/main.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ mod github_repo;
55
mod package_json;
66
mod vpm;
77

8-
use std::io;
8+
use std::{fs::File, io};
99

1010
use clap::Parser;
1111

12-
use crate::{args::Args, cache::Cache, generator::VpmRepoGenerator};
12+
use crate::{
13+
args::{Args, STDIN},
14+
cache::Cache,
15+
generator::VpmRepoGenerator,
16+
};
1317

1418
#[tokio::main]
1519
async fn main() -> Result<(), anyhow::Error> {
@@ -32,7 +36,12 @@ async fn main() -> Result<(), anyhow::Error> {
3236

3337
cache.save()?;
3438

35-
serde_json::to_writer_pretty(io::stdout(), &vpm_repos)?;
39+
if args.output.as_str() == STDIN {
40+
serde_json::to_writer_pretty(io::stdout(), &vpm_repos)?;
41+
} else {
42+
let f = File::create(&args.output)?;
43+
serde_json::to_writer_pretty(f, &vpm_repos)?;
44+
}
3645

3746
Ok(())
3847
}

0 commit comments

Comments
 (0)