cat : --base

This commit is contained in:
bth 2026-01-21 14:11:30 -08:00
commit a3ea15e3eb

View file

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/brtholomy/um/go/cmd"
@ -19,19 +20,22 @@ const (
type options struct {
Filelist flags.Arg
Base flags.Flag[string]
Help flags.Flag[bool]
}
func initOpts() options {
return options{
flags.Arg{"", "filelist. accepts from stdin if not provided"},
flags.Flag[string]{"--base", "-b", "", "base directory prepended to files in filelist"},
flags.Flag[bool]{"--help", "-h", false, "show help"},
}
}
func cat(files []string) (string, error) {
func cat(files []string, base string) (string, error) {
ff := make([]string, 0, len(files))
for _, f := range files {
f := filepath.Join(base, f)
dat, err := os.ReadFile(f)
if err != nil {
return "", fmt.Errorf("error opening target file: %w", err)
@ -48,7 +52,7 @@ func Cat(args []string) {
if err != nil {
log.Fatalf("um %s: %s", CMD, err)
}
s, err := cat(files)
s, err := cat(files, opts.Base.Val)
if err != nil {
log.Fatalf("um %s: %s", CMD, err)
}