From bd2b435e7cd782cacfc4c74af3573de7a1791c8e Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 4 Oct 2024 17:11:19 +0200 Subject: chore: Initial Commit --- src/main.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..a6b047b --- /dev/null +++ b/src/main.rs @@ -0,0 +1,39 @@ +// Copyright (C) 2024 Benedikt Peetz +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// This file is part of Quotify - A simple CLI utility to shell quote the text +// inputted into it. +// +// You should have received a copy of the License along with this program. +// If not, see . + +use std::{ + env::args, + io::{stdin, Read}, +}; + +use anyhow::{Context, Result}; + +fn main() -> Result<()> { + let text: String = { + if args().count() != 1 { + args().skip(1).collect() + } else { + let mut stdin = stdin(); + let mut buf = vec![]; + stdin + .read_to_end(&mut buf) + .context("Failed to read stdin")?; + + let output = + String::from_utf8(buf).context("Failed to decode stdin as a utf8 string")?; + output + } + }; + + let quoted_text = text.replace('\'', "'\\''"); + + print!("'{}'", quoted_text); + + Ok(()) +} -- cgit 1.4.1