// 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(()) }