And process any number of files.

master
Zed A. Shaw 3 weeks ago
parent e978ca4e7f
commit 1f8a28c041
  1. 11
      cat/main.go

@ -17,7 +17,7 @@ func Fail(err error, format string, v ...any) {
type Opts struct { type Opts struct {
Number bool Number bool
Squeeze bool Squeeze bool
Filename string Filenames []string
} }
func parse_opts() (Opts) { func parse_opts() (Opts) {
@ -32,16 +32,18 @@ func parse_opts() (Opts) {
os.Exit(1) os.Exit(1)
} }
opts.Filename = flag.Arg(0) opts.Filenames = flag.Args()
return opts return opts
} }
func main() { func main() {
opts := parse_opts() opts := parse_opts()
in_file, err := os.ReadFile(opts.Filename)
if err != nil { Fail(err, "cannot open %s:", opts.Filename) } for _, filename := range opts.Filenames {
in_file, err := os.ReadFile(filename)
if err != nil { Fail(err, "cannot open %s:", filename) }
if(opts.Number) { if(opts.Number) {
count := 1 count := 1
@ -57,3 +59,4 @@ func main() {
fmt.Print(string(in_file)) fmt.Print(string(in_file))
} }
} }
}

Loading…
Cancel
Save