// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

package main

import (
	"flag"
	"fmt"
	"os"
)

func main() {
	flag.Parse()

	args := flag.Args()

	if opt.version {
		fmt.Printf("glzip %v\n", version)
		os.Exit(0)
	}

	if flag.NArg() < 1 {
		flag.Usage()
		os.Exit(1)
	}

	output := os.Stdout

	if opt.stdout {
		opt.keep = true
	}

	if !opt.decompress {
		for _, file := range args {
			err := compress(file, output, opt)
			if err != nil {
				fmt.Fprintf(os.Stderr, "glzip: %v\n", err)
				os.Exit(1)
			}
		}
	} else {
		for _, file := range args {
			err := uncompress(file, output, opt)
			if err != nil {
				fmt.Fprintf(os.Stderr, "glzip: %v\n", err)
				os.Exit(1)
			}
		}
	}
}
