Skip to content

Commit

Permalink
Specified output location type as file/database
Browse files Browse the repository at this point in the history
  • Loading branch information
samirgadkari committed Jan 25, 2022
1 parent 09c4612 commit 1a8b45e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
14 changes: 13 additions & 1 deletion cli/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Copyright © 2022 Samir Gadkari
package cmd

import (
"fmt"
"path/filepath"

"github.com/samirgadkari/search/pkg/config"
"github.com/samirgadkari/search/pkg/transform"
"github.com/spf13/cobra"
Expand All @@ -20,6 +23,15 @@ If it is a list of documents, don't include the [] list specifiers. ex:
{"review_id": 2, "text": "User review for ID 2"}`,
Run: func(cmd *cobra.Command, args []string) {
cfg := config.LoadConfig()
fmt.Printf("%#v\n", cfg)
var outputDir = ""
var wordIntsFile = ""
if cfg.Output.Type == config.File.String() {
outputDir = filepath.Dir(cfg.Output.Location)
wordIntsFile = filepath.Base(cfg.Output.Location)
}

fmt.Printf("outputDir: %s\nwordIntsFile: %s\n", outputDir, wordIntsFile)

stopWords := config.LoadStopwords(cfg)

Expand All @@ -31,7 +43,7 @@ If it is a list of documents, don't include the [] list specifiers. ex:
}

transform.WordsToInts(stopWords, dataFile,
cfg.OutputDir, cfg.WordIntsFile)
outputDir, wordIntsFile)
},
}

Expand Down
19 changes: 17 additions & 2 deletions pkg/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ import (
"github.com/spf13/viper"
)

type OutputLocationType int

const (
File OutputLocationType = iota
Database
)

func (o OutputLocationType) String() string {
return [...]string{"file", "database"}[o]
}

type OutputConfig struct {
Type string
Location string
}

type Config struct {
OriginalFile string
DataFile string
EnglishStopwordsFile string
OutputDir string
WordIntsFile string
Output OutputConfig
}

func LoadConfig() *Config {
Expand Down

0 comments on commit 1a8b45e

Please sign in to comment.