@@ -10,6 +10,9 @@ import (
1010
1111 "github.com/hedhyw/json-log-viewer/internal/app"
1212 "github.com/hedhyw/json-log-viewer/internal/pkg/config"
13+ "github.com/hedhyw/json-log-viewer/internal/pkg/source"
14+ "github.com/hedhyw/json-log-viewer/internal/pkg/source/fileinput"
15+ "github.com/hedhyw/json-log-viewer/internal/pkg/source/readerinput"
1316)
1417
1518const configFileName = ".jlv.jsonc"
@@ -18,16 +21,23 @@ func main() {
1821 configPath := flag .String ("config" , "" , "Path to the config" )
1922 flag .Parse ()
2023
21- if flag .NArg () != 1 {
22- fatalf ("Invalid arguments, usage: %s file.log\n " , os .Args [0 ])
23- }
24-
2524 cfg , err := readConfig (* configPath )
2625 if err != nil {
2726 fatalf ("Error reading config: %s\n " , err )
2827 }
2928
30- appModel := app .NewModel (flag .Args ()[0 ], cfg )
29+ var sourceInput source.Input
30+
31+ switch flag .NArg () {
32+ case 0 :
33+ sourceInput = readerinput .New (os .Stdin , cfg .StdinReadTimeout )
34+ case 1 :
35+ sourceInput = fileinput .New (flag .Arg (0 ))
36+ default :
37+ fatalf ("Invalid arguments, usage: %s file.log\n " , os .Args [0 ])
38+ }
39+
40+ appModel := app .NewModel (sourceInput , cfg )
3141 program := tea .NewProgram (appModel , tea .WithAltScreen ())
3242
3343 if _ , err := program .Run (); err != nil {
0 commit comments