Skip to content

Commit

Permalink
Cleaned cmd index
Browse files Browse the repository at this point in the history
  • Loading branch information
Avokadoen committed Mar 15, 2021
1 parent 03c1e7f commit c9a3be4
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions cmd/warcserver/cmd/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func parseFormat(format string) (index.CdxWriter, error) {
type conf struct {
fileName string
writerFormat string
writer index.CdxWriter
}

func NewCommand() *cobra.Command {
Expand All @@ -65,14 +64,16 @@ func NewCommand() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
c.fileName = args[0]

var err error
c.writer, err = parseFormat(c.writerFormat)
writer, err := parseFormat(c.writerFormat)
if err != nil {
return err
}
c.writer.Init()

return runE(c)
writer.Init()
defer writer.Close()
fmt.Printf("Format: %v\n", c.writerFormat)

return readFile(c.fileName, writer)
},
}

Expand All @@ -81,16 +82,9 @@ func NewCommand() *cobra.Command {
return cmd
}

func runE(c *conf) error {
defer c.writer.Close()
fmt.Printf("Format: %v\n", c.writerFormat)

return readFile(c)
}

func readFile(c *conf) error {
func readFile(fileName string, writer index.CdxWriter) error {
opts := &warcoptions.WarcOptions{Strict: false}
wf, err := warcreader.NewWarcFilename(c.fileName, 0, opts)
wf, err := warcreader.NewWarcFilename(fileName, 0, opts)
if err != nil {
return err
}
Expand All @@ -114,7 +108,7 @@ func readFile(c *conf) error {
}
count++

c.writer.Write(wr, c.fileName, currentOffset)
writer.Write(wr, fileName, currentOffset)
}
return nil
}

0 comments on commit c9a3be4

Please sign in to comment.