feat: tokenizer
This commit is contained in:
28
pkg/cli/arguments.go
Normal file
28
pkg/cli/arguments.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
)
|
||||
|
||||
type CLIOptions struct {
|
||||
Input string
|
||||
}
|
||||
|
||||
func ParseOptions(args []string) (*CLIOptions, error) {
|
||||
slog.Info("Parsing CLI arguments.", "args", os.Args)
|
||||
|
||||
// Parse flags and arguments.
|
||||
flag.Parse()
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
return nil, fmt.Errorf("No input given.")
|
||||
case 1:
|
||||
return &CLIOptions{Input: flag.Arg(0)}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("More than 1 command-line argument.")
|
||||
}
|
||||
}
|
||||
15
pkg/cli/exit.go
Normal file
15
pkg/cli/exit.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func HandleError(err error) {
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
Reference in New Issue
Block a user