Skip to content

Commit 5cfc860

Browse files
committed
feat: Atty input serialization
1 parent 18c585b commit 5cfc860

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
22
name = "ice"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["tamton-aquib <[email protected]>"]
66
license = "MIT"
7-
description = "A simple CTF tool set"
7+
description = "A simple CTF tool store"
88
homepage = "https://github.com/tamton-aquib/ice"
99
repository = "https://github.com/tamton-aquib/ice"
1010
readme = "README.md"

PKGBUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Maintainer: Aquib Javed <[email protected]>
22
pkgname=ice-bin
3-
pkgver=0.2.1
3+
pkgver=0.3.0
44
pkgrel=1
55
epoch=
6-
pkgdesc="A lightweight CTF utility."
6+
pkgdesc="A simple CTF tool store."
77
arch=('x86_64' 'i686')
88
url="https://github.com/tamton-aquib/ice"
99
license=('MIT')
1010
makedepends=()
1111
options=()
1212
install=
1313
changelog=
14-
source=("ice.zip::https://github.com/tamton-aquib/ice/releases/download/v${pkgver}/ice-x86_64-unknown-linux-gnu.tar.gz")
14+
source=("ice-x86_64-unknown-linux-gnu.tar.gz::https://github.com/tamton-aquib/ice/releases/download/v${pkgver}/ice-x86_64-unknown-linux-gnu.tar.gz")
1515
noextract=()
1616
noextract=()
1717
sha256sums=('SKIP')
1818

1919
package() {
2020
tar -xzf "${srcdir}/ice-x86_64-unknown-linux-gnu.tar.gz" -C "${srcdir}"
21-
install -Dm755 "${srcdir}/ice-x86_64-unknown-linux-gnu/ice" "${pkgdir}/usr/bin/ice"
21+
install -Dm755 "${srcdir}/ice" "${pkgdir}/usr/bin/ice"
2222
}

src/main.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
use pico_args::Arguments;
2-
1+
use atty::Stream;
32
use ice::app::cli::{parse_args, Command};
3+
use pico_args::Arguments;
4+
use std::{
5+
ffi::OsString,
6+
io::{self, Read},
7+
};
48

59
fn print_usage() {
6-
println!("ICE - A command-line tool for various ciphers, encoding, and text manipulation.\n");
7-
println!("USAGE:");
8-
println!(" ice <SUBCOMMAND> [ARGUMENTS]");
9-
println!(" ice help");
10-
println!("\nFor a list of available subcommands, run `ice help`.");
10+
println!("ICE - A simple CTF tool store.");
11+
println!("Usage: ice <SUBCOMMAND> [ARGUMENTS]");
12+
println!("Run 'ice help' for a list of available subcommands");
1113
}
1214

1315
fn main() {
14-
let mut args = Arguments::from_env();
16+
let mut args: Vec<OsString> = std::env::args_os().skip(1).collect();
17+
18+
if !atty::is(Stream::Stdin) {
19+
let mut input = String::new();
20+
io::stdin().read_to_string(&mut input).unwrap();
21+
let input = input.trim();
22+
if !input.is_empty() {
23+
args.push(OsString::from(input));
24+
}
25+
}
26+
27+
let mut args = Arguments::from_vec(args);
1528

1629
let command = match parse_args(&mut args) {
1730
Ok(cmd) => cmd,
@@ -23,18 +36,12 @@ fn main() {
2336
};
2437

2538
match command {
26-
Command::Help => {
27-
print_usage();
28-
}
29-
Command::Version => {
30-
println!("ice {}", env!("CARGO_PKG_VERSION"));
31-
}
39+
Command::Help => print_usage(),
40+
Command::Version => println!("ice {}", env!("CARGO_PKG_VERSION")),
3241
Command::Unknown(cmd) => {
3342
eprintln!("Error: Unknown subcommand '{}'", cmd);
3443
print_usage();
3544
}
36-
_ => {
37-
command.run();
38-
}
45+
_ => command.run(),
3946
}
4047
}

0 commit comments

Comments
 (0)