mirror of
https://github.com/walles/moar.git
synced 2024-11-27 11:03:58 +03:00
Add initial option parsing support
This commit is contained in:
parent
2f5c2da2e3
commit
92b0133b25
30
moar.go
30
moar.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@ -16,6 +17,18 @@ import (
|
||||
func main() {
|
||||
// FIXME: On any panic or warnings, also print system info and how to report bugs
|
||||
|
||||
version := flag.Bool("version", false, "Prints the moar version number")
|
||||
|
||||
// FIXME: Support --help
|
||||
|
||||
// FIXME: Support --no-highlight
|
||||
|
||||
flag.Parse()
|
||||
if *version {
|
||||
fmt.Println("FIXME: Imagine a version string here")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
stdinIsRedirected := !terminal.IsTerminal(int(os.Stdin.Fd()))
|
||||
stdoutIsRedirected := !terminal.IsTerminal(int(os.Stdout.Fd()))
|
||||
if stdinIsRedirected && stdoutIsRedirected {
|
||||
@ -34,21 +47,18 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// FIXME: Support --help
|
||||
|
||||
// FIXME: Support --version
|
||||
|
||||
// FIXME: Support --no-highlight
|
||||
|
||||
if len(os.Args) != 2 {
|
||||
if len(flag.Args()) != 1 {
|
||||
// FIXME: Improve this message
|
||||
fmt.Fprintf(os.Stderr, "ERROR: Expected exactly one parameter, got: %v\n", os.Args[1:])
|
||||
fmt.Fprintln(os.Stderr, "ERROR: Expected exactly one filename, got: ", flag.Args())
|
||||
|
||||
// FIXME: Print full usage here
|
||||
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if stdoutIsRedirected {
|
||||
// Pump from file by given name onto stdout which is redirected
|
||||
input, err := os.Open(os.Args[1])
|
||||
input, err := os.Open(flag.Arg(0))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %s\n", err)
|
||||
os.Exit(1)
|
||||
@ -61,7 +71,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Display the input file contents
|
||||
reader, err := m.NewReaderFromFilename(os.Args[1])
|
||||
reader, err := m.NewReaderFromFilename(flag.Arg(0))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
Reference in New Issue
Block a user