diff --git a/docs/mm.1 b/docs/mm.1 index 9aa69f5..a2419da 100644 --- a/docs/mm.1 +++ b/docs/mm.1 @@ -4,7 +4,7 @@ .\" This work is licensed under CC BY-SA 4.0. To see a copy of this license, .\" visit . .\" -.TH MM 1 2024-07-14 "Harakit X.X.X" +.TH MM 1 2025-11-01 "Harakit X.X.X" .SH NAME mm \(en middleman .\" @@ -22,7 +22,9 @@ Catenate input files and write them to the start of each output file or stream. .SH OPTIONS .IP \fB-a\fP -Opens outputs for appending rather than updating. +Opens outputs for appending rather than updating. Implies the +.B -t +option. .IP \fB-e\fP Use the standard error as an output. .IP \fB-t\fP @@ -59,6 +61,10 @@ unncessary. .\" .SH HISTORY +The \fB-t\fP option was originally the reverse functionality, as the default +behavior was to overwrite outputs. This was deemed counterintuitive and the +default behavior was changed. + This utility originally had a \fB-u\fP option for compatibility with cat(1p), but this option is almost always default behavior in practice; therefore, it was dropped both for simplicity and to expand the diff --git a/src/mm.rs b/src/mm.rs index 9ad4cb8..42a4fad 100644 --- a/src/mm.rs +++ b/src/mm.rs @@ -168,7 +168,7 @@ fn main() -> ExitCode { let options = File::options() /* don’t truncate if -t is specified, append if -a is specified */ - .truncate(t) + .truncate(!a && t) .append(a) /* enable the ability to create and write to files */ .create(true) diff --git a/tests/mm.mk b/tests/mm.mk index 11f83fa..1413cbd 100755 --- a/tests/mm.mk +++ b/tests/mm.mk @@ -1,10 +1,12 @@ -# Copyright (c) 2024 Emma Tebibyte +# Copyright (c) 2024–2025 Emma Tebibyte # SPDX-License-Identifier: FSFAP # # Copying and distribution of this file, with or without modification, are # permitted in any medium without royalty provided the copyright notice and # this notice are preserved. This file is offered as-is, without any warranty. +MM_FILE!=mktemp /tmp/mm.XXXXXX + .PHONY: mm_tests mm_tests: mm_args mm_help mm_stderr mm_remaining mm_remaining_options @@ -38,3 +40,18 @@ mm_remaining: $(BIN)/mm mm_remaining_options: ! $(BIN)/mm -i README COPYING -o - 2>&1 | cut -d: -f2 \ | xargs test " -o" = + +.PHONY: mm_append +mm_append: + $(BIN)/mm -i /dev/null -o $(MM_FILE) + printf 'test\nstring\nmulti-line\n' | $(BIN)/mm -o $(MM_FILE) + printf 'new line\n' | $(BIN)/mm -a -o $(MM_FILE) + $(BIN)/mm -i $(MM_FILE) | wc -l | xargs test 4 -eq + +.PHONY: mm_no_truncate +mm_no_truncate: + $(BIN)/mm -i /dev/null -o $(MM_FILE) + printf 'test\nstring\nmulti-line\n' | $(BIN)/mm -o $(MM_FILE) + printf 'new line\n' | $(BIN)/mm -t -o $(MM_FILE) + $(BIN)/mm -i $(MM_FILE) | wc -l | xargs test 3 -eq +