diff --git a/challenge-01/analyzer/reader.go b/challenge-01/analyzer/reader.go index 0a98ada..bfdfda1 100644 --- a/challenge-01/analyzer/reader.go +++ b/challenge-01/analyzer/reader.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/priyanshsao/coding-challenges-go/challenge-01/config" + "github.com/sirupsen/logrus" ) // ipMode represents input mode @@ -16,6 +17,18 @@ const ( STD_IN ) +func (ipM ipMode) String() string { + + switch ipM { + case TERMINAL: + return "Terminal" + case STD_IN: + return "Standard input" + } + + return "" +} + // Read reads the input and stores it in Config. func Read(c *config.Config) error { @@ -29,7 +42,7 @@ func Read(c *config.Config) error { switch mode { case TERMINAL: if len(c.Args) == 0 { - // Todo: add debug. + logrus.Debugf("unable to read: %s", ErrNoArgProvided) return ErrNoArgProvided } reader, err = readTerm(c.Args[0]) @@ -50,20 +63,23 @@ func getIpMode() (ipMode, error) { stat, err := os.Stdin.Stat() if err != nil { - // Todo: add debug here + logrus.Debugf("unable to get input mode: %v", err) return -1, err } if (stat.Mode() & os.ModeCharDevice) == 0 { + logrus.Debugf("input mode detected: %v", STD_IN) return STD_IN, nil } + logrus.Debugf("input mode detected: %v", TERMINAL) return TERMINAL, nil } func readTerm(filePath string) (*os.File, error) { if trimmedFpath := strings.TrimSpace(filePath); trimmedFpath == "" { + logrus.Debugf("unable to read from terminal: %s", ErrEmptyFilePath) return nil, ErrEmptyFilePath } diff --git a/challenge-01/cmd/ccwc.go b/challenge-01/cmd/ccwc.go index d51a7d7..e5e18ec 100644 --- a/challenge-01/cmd/ccwc.go +++ b/challenge-01/cmd/ccwc.go @@ -40,7 +40,7 @@ func main() { c.Args = flag.CommandLine.Args() if flag.NFlag() == 0 { - // Todo: add debug logs + logrus.Debugf("no flags provided, using defaults.") opts[config.BYTES] = true opts[config.LINES] = true @@ -63,14 +63,17 @@ func main() { return } - fmt.Println(c.Result) + logrus.Info(c.Result) } func setLogger() { - // remove unwanted things and enforce colors + // remove unwanted things and enforce colors. logrus.SetFormatter(&logrus.TextFormatter{ ForceColors: true, DisableLevelTruncation: true, }) + + // set log level to debug. + logrus.SetLevel(logrus.DebugLevel) }