Skip to content

Commit

Permalink
apply: --repo-file can now be stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Dec 14, 2023
1 parent fc269a6 commit 5a54135
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.6.0 (in development)
-----------------------
- `apply`: The argument to `--repo-file` can now be `-` to read from standard
input

v0.5.0 (2023-11-06)
-------------------
- The log message emitted before each API request is now emitted after the log
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "labelmaker"
version = "0.5.0"
version = "0.6.0-dev"
edition = "2021"
rust-version = "1.70"
description = "Create & enforce sets of labels in GitHub repositories"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ made.
showing what would be changed.

- `-F FILE`/`--repo-file FILE` — Also operate on all repositories listed in the
given file. Repositories must be listed one per line. Leading & trailing
whitespace is ignored. Blank lines and lines starting with `#` are skipped.
given file (or listed on standard input if `FILE` is `-`). Repositories must
be listed one per line. Leading & trailing whitespace is ignored. Blank
lines and lines starting with `#` are skipped.

- `-P NAME`/`--profile NAME` — Specify which profile in the configuration file
to use. Defaults to the value of `defaults.profile` in the configuration
Expand Down
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use anyhow::Context;
use clap::{builder::ArgAction, Args, Parser, Subcommand};
use ghrepo::{GHRepo, LocalRepo};
use log::{Level, LevelFilter};
use std::io::{self, BufRead};
use std::io;
use std::path::PathBuf;
use std::process::ExitCode;

Expand Down Expand Up @@ -66,7 +66,7 @@ enum Command {
/// whitespace is ignored. Blank lines and lines starting with '#' are
/// skipped.
#[arg(short = 'F', long, value_name = "FILE")]
repo_file: Option<PathBuf>,
repo_file: Option<patharg::InputArg>,

/// A configuration file describing what labels to create and/or update
/// in each repository
Expand Down Expand Up @@ -124,11 +124,9 @@ impl Command {
};
let mut repo_parser = RepoParser::new(&client);
if let Some(p) = repo_file {
let fp = std::fs::File::open(&p)
.with_context(|| format!("failed to open {}", p.display()))?;
for ln in io::BufReader::new(fp).lines() {
let ln =
ln.with_context(|| format!("failed to read from {}", p.display()))?;
let lines = p.lines().with_context(|| format!("failed to open {p:#}"))?;
for ln in lines {
let ln = ln.with_context(|| format!("failed to read from {p:#}"))?;
let ln = ln.trim();
if !(ln.is_empty() || ln.starts_with('#')) {
repository.push(ln.to_owned());
Expand Down

0 comments on commit 5a54135

Please sign in to comment.