From 8aa26300142ca9822cefeb493dbdf505c3e287aa Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 1 Jul 2026 10:26:12 +0200 Subject: [PATCH] tsort: remove unreachable error case --- src/uu/tsort/locales/en-US.ftl | 3 +-- src/uu/tsort/locales/fr-FR.ftl | 3 +-- src/uu/tsort/src/tsort.rs | 37 +++++++++++++++------------------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/uu/tsort/locales/en-US.ftl b/src/uu/tsort/locales/en-US.ftl index 2b2f90a1e01..41a36a08fa9 100644 --- a/src/uu/tsort/locales/en-US.ftl +++ b/src/uu/tsort/locales/en-US.ftl @@ -7,5 +7,4 @@ tsort-error-is-dir = read error: Is a directory tsort-error-odd = input contains an odd number of tokens tsort-error-loop = input contains a loop: tsort-error-extra-operand = extra operand { $operand } - Try '{ $util } --help' for more information. -tsort-error-at-least-one-input = at least one input + Try 'tsort --help' for more information. diff --git a/src/uu/tsort/locales/fr-FR.ftl b/src/uu/tsort/locales/fr-FR.ftl index c3594e7a212..e43aab26aed 100644 --- a/src/uu/tsort/locales/fr-FR.ftl +++ b/src/uu/tsort/locales/fr-FR.ftl @@ -7,5 +7,4 @@ tsort-error-is-dir = erreur de lecture : c'est un répertoire tsort-error-odd = l'entrée contient un nombre impair de jetons tsort-error-loop = l'entrée contient une boucle : tsort-error-extra-operand = opérande supplémentaire { $operand } - Essayez '{ $util } --help' pour plus d'informations. -tsort-error-at-least-one-input = au moins une entrée + Essayez 'tsort --help' pour plus d'informations. diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 1e0121d6a31..d59cefada0c 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -2,8 +2,10 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -//spell-checker:ignore TAOCP indegree FADV -//spell-checker:ignore (libs) interner uclibc + +// spell-checker:ignore TAOCP indegree +// spell-checker:ignore (libs) interner + use clap::{Arg, ArgAction, Command}; use rustc_hash::FxHashMap; use std::collections::VecDeque; @@ -35,25 +37,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { .into_iter() .flatten(); - let input = match (inputs.next(), inputs.next()) { - (None, _) => { - return Err(USimpleError::new( - 1, - translate!("tsort-error-at-least-one-input"), - )); - } - (Some(input), None) => input, - (Some(_), Some(extra)) => { - return Err(USimpleError::new( - 1, - translate!( - "tsort-error-extra-operand", - "operand" => extra.quote(), - "util" => "tsort" - ), - )); - } - }; + let input = inputs.next().expect("default value should be set by clap"); + + if let Some(extra) = inputs.next() { + return Err(USimpleError::new( + 1, + translate!( + "tsort-error-extra-operand", + "operand" => extra.quote() + ), + )); + } + // Create the directed graph from pairs of tokens in the input data. let mut g = Graph::new(input.to_string_lossy().to_string()); if input == "-" {