11package main
22
33import (
4+ "flag"
45 "fmt"
56 "os"
67 "path"
@@ -14,16 +15,19 @@ import (
1415const configFileName = ".jlv.jsonc"
1516
1617func main () {
17- if len (os .Args ) != 2 {
18+ configPath := flag .String ("config" , "" , "Path to the config" )
19+ flag .Parse ()
20+
21+ if flag .NArg () != 1 {
1822 fatalf ("Invalid arguments, usage: %s file.log\n " , os .Args [0 ])
1923 }
2024
21- cfg , err := readConfig ()
25+ cfg , err := readConfig (* configPath )
2226 if err != nil {
2327 fatalf ("Error reading config: %s\n " , err )
2428 }
2529
26- appModel := app .NewModel (os .Args [ 1 ], cfg )
30+ appModel := app .NewModel (flag .Args ()[ 0 ], cfg )
2731 program := tea .NewProgram (appModel , tea .WithAltScreen ())
2832
2933 if _ , err := program .Run (); err != nil {
@@ -38,9 +42,13 @@ func fatalf(message string, args ...any) {
3842
3943// readConfig tries to read config from working directory or home directory.
4044// If configs are not found, then it returns a default configuration.
41- func readConfig () (* config.Config , error ) {
45+ func readConfig (configPath string ) (* config.Config , error ) {
4246 paths := []string {}
4347
48+ if configPath != "" {
49+ paths = append (paths , configPath )
50+ }
51+
4452 workDir , err := os .Getwd ()
4553 if err == nil {
4654 paths = append (paths , path .Join (workDir , configFileName ))
0 commit comments