Skip to content

Commit

Permalink
fix: remove helpers internal and use only utils
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsm-dev committed Jun 17, 2022
1 parent 66629a0 commit c766146
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 150 deletions.
4 changes: 1 addition & 3 deletions commands/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"

//"github.com/common-nighthawk/go-figure"
"github.com/lpmatos/loli/internal/constants"
log "github.com/lpmatos/loli/internal/log"
"github.com/lpmatos/loli/internal/utils"
Expand All @@ -20,12 +19,11 @@ var (
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by loli main(). It only needs to happen once to the rootCmd.
func Execute() {
//figure.NewColorFigure(constants.BinaryName, "smslant", "yellow", false).Print()

outputRender, err := utils.RenderMarkdown(constants.Welcome)
if err != nil {
log.Fatal("Render glamour markdown")
}

fmt.Print(outputRender)

if err := rootCmd.Execute(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package commands
import (
"github.com/lpmatos/loli/internal/constants"
"github.com/lpmatos/loli/internal/debug"
"github.com/lpmatos/loli/internal/helpers"
log "github.com/lpmatos/loli/internal/log"
"github.com/lpmatos/loli/internal/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -42,7 +42,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&config.Level, "log-level", "debug", "set the logging level. One of: debug|info|warn|error")
rootCmd.PersistentFlags().StringVar(&config.Format, "log-format", "color", "the formating of the logs. Available values: text|color|json|json-pretty")
rootCmd.PersistentFlags().StringVar(&config.Output, "log-output", "stdout", "default log output. Available values: stdout|stderr|file")
rootCmd.PersistentFlags().StringVar(&config.File, "log-file", helpers.CreateLogFile("/var/log/loli", "file"), "defaulting Loli CLI log file")
rootCmd.PersistentFlags().StringVar(&config.File, "log-file", utils.CreateLogFile("/var/log/loli", "file"), "defaulting Loli CLI log file")
rootCmd.PersistentFlags().BoolVarP(&config.Verbose, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().IntP("timeout", "t", 0, "override the default HTTP timeout (seconds)")
}
4 changes: 1 addition & 3 deletions internal/api/types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package api

import (
"net/http"
)
import "net/http"

// Client struct - is an http client that is configured for API.
type Client struct {
Expand Down
90 changes: 0 additions & 90 deletions internal/helpers/helpers.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func applyOptions(opts []Option) *options {
return &o
}

// Setup returns a new logrus instance.
// Setup returns a new logrus instance
func Setup(opts ...Option) error {
conf := applyOptions(opts)
conf.logger.SetFormatter(conf.logger.Formatter)
Expand Down
4 changes: 2 additions & 2 deletions internal/log/logger_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package log

// Config defines all the configurable options for the logrus logger.
// Config defines all the configurable options for the logrus logger
type Config struct {
Level string
Format string
Expand All @@ -9,7 +9,7 @@ type Config struct {
Verbose bool
}

// SetDefault set default values for logrus logger configurable options.
// SetDefault set default values for logrus logger configurable options
func (config *Config) SetDefault(level, formater, output, file string, verbose bool) {
config.Level = level
config.Format = formater
Expand Down
6 changes: 3 additions & 3 deletions internal/log/logger_formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/sirupsen/logrus"
)

// Configure the logrus format to use "text" formatter.
// Configure the logrus format to use "text" formatter
func textFormatter() *logrus.TextFormatter {
return &logrus.TextFormatter{
DisableColors: true,
Expand All @@ -17,7 +17,7 @@ func textFormatter() *logrus.TextFormatter {
}
}

// Configure the logrus format to use "color" formatter.
// Configure the logrus format to use "color" formatter
func colorFormatter() *logrus.TextFormatter {
return &logrus.TextFormatter{
DisableColors: false,
Expand All @@ -29,7 +29,7 @@ func colorFormatter() *logrus.TextFormatter {
}
}

// Configure the logrus format to use "json" formatter.
// Configure the logrus format to use "json" formatter
func jsonFormatter(pretty bool) *logrus.JSONFormatter {
return &logrus.JSONFormatter{
TimestampFormat: constants.DefaultTimestampFormat,
Expand Down
30 changes: 15 additions & 15 deletions internal/log/logger_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
au "github.com/logrusorgru/aurora/v3"
)

// Debug function to print a pretty formatted log debug message.
// Debug function to print a pretty formatted log debug message
func Debug(args ...interface{}) {
logger.Debug(
au.BrightCyan(
Expand All @@ -16,7 +16,7 @@ func Debug(args ...interface{}) {
)
}

// Debugf function to print a pretty formatted log debug message.
// Debugf function to print a pretty formatted log debug message
func Debugf(format string, args ...interface{}) {
logger.Debugf(
"🆗 "+au.BrightCyan(format).
Expand All @@ -26,7 +26,7 @@ func Debugf(format string, args ...interface{}) {
)
}

// Debugln function to print a pretty formatted log debug message.
// Debugln function to print a pretty formatted log debug message
func Debugln(args ...interface{}) {
logger.Debugln(
au.BrightCyan(
Expand All @@ -35,7 +35,7 @@ func Debugln(args ...interface{}) {
)
}

// Info function to print a pretty formatted log info message.
// Info function to print a pretty formatted log info message
func Info(args ...interface{}) {
logger.Info(
au.Green(
Expand All @@ -44,7 +44,7 @@ func Info(args ...interface{}) {
)
}

// Infof function to print a pretty formatted log info message.
// Infof function to print a pretty formatted log info message
func Infof(format string, args ...interface{}) {
logger.Infof(
"✅ "+au.Green(format).
Expand All @@ -54,7 +54,7 @@ func Infof(format string, args ...interface{}) {
)
}

// Infoln function to print a pretty formatted log info message.
// Infoln function to print a pretty formatted log info message
func Infoln(args ...interface{}) {
logger.Infoln(
au.Green(
Expand All @@ -63,7 +63,7 @@ func Infoln(args ...interface{}) {
)
}

// Warn function to print a pretty formatted log warn message.
// Warn function to print a pretty formatted log warn message
func Warn(args ...interface{}) {
logger.Warn(
au.BrightYellow(
Expand All @@ -72,7 +72,7 @@ func Warn(args ...interface{}) {
)
}

// Warnf function to print a pretty formatted log warn message.
// Warnf function to print a pretty formatted log warn message
func Warnf(format string, args ...interface{}) {
logger.Warnf(
"😲 "+au.BrightYellow(format).
Expand All @@ -82,7 +82,7 @@ func Warnf(format string, args ...interface{}) {
)
}

// Warnln function to print a pretty formatted log warn message.
// Warnln function to print a pretty formatted log warn message
func Warnln(args ...interface{}) {
logger.Warnln(
au.BrightYellow(
Expand All @@ -91,15 +91,15 @@ func Warnln(args ...interface{}) {
)
}

// Error function to print a pretty formatted log error message.
// Error function to print a pretty formatted log error message
func Error(args ...interface{}) {
logger.Error(
au.BrightRed(
emoji.Sprintf("😡 " + fmt.Sprintf("%v", args...)),
))
}

// Errorf function to print a pretty formatted log error message.
// Errorf function to print a pretty formatted log error message
func Errorf(format string, args ...interface{}) {
logger.Errorf(
"😡 "+au.BrightRed(format).
Expand All @@ -109,7 +109,7 @@ func Errorf(format string, args ...interface{}) {
)
}

// Errorln function to print a pretty formatted log error message.
// Errorln function to print a pretty formatted log error message
func Errorln(args ...interface{}) {
logger.Errorln(
au.BrightRed(
Expand All @@ -118,15 +118,15 @@ func Errorln(args ...interface{}) {
)
}

// Fatal function to print a pretty formatted log fatal message.
// Fatal function to print a pretty formatted log fatal message
func Fatal(args ...interface{}) {
logger.Fatal(
au.BrightRed(
emoji.Sprintf("🤬 " + fmt.Sprintf("%v", args...)),
))
}

// Fatalf function to print a pretty formatted log fatal message.
// Fatalf function to print a pretty formatted log fatal message
func Fatalf(format string, args ...interface{}) {
logger.Fatalf(
"🤬 "+au.BrightRed(format).
Expand All @@ -136,7 +136,7 @@ func Fatalf(format string, args ...interface{}) {
)
}

// Fatalln function to print a pretty formatted log fatal message.
// Fatalln function to print a pretty formatted log fatal message
func Fatalln(args ...interface{}) {
logger.Fatalln(
au.BrightRed(
Expand Down
12 changes: 6 additions & 6 deletions internal/log/logger_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type options struct {
logger *logrus.Logger
}

// Option will configure a new logrus Logger.
// Option will configure a new logrus Logger
type Option func(*options) error

// WithConfig takes the logger configuration and applies it.
// WithConfig takes the logger configuration and applies it
func WithConfig(cfg Config) Option {
var opts []Option

Expand Down Expand Up @@ -64,7 +64,7 @@ func WithFormatter(format string) Option {
}

// WithLogLevel is used to set the log level when defaulting to `info` is not
// wanted. Other options are: `debug`, `info`, `warn` and `error`.
// wanted. Other options are: `debug`, `info`, `warn` and `error`
func WithLogLevel(level string, verbose bool) Option {
return func(opt *options) error {
logrusLevel, err := logrus.ParseLevel(level)
Expand All @@ -81,7 +81,7 @@ func WithLogLevel(level string, verbose bool) Option {
}

// WithOutputStr allows customization of the sink of the logger. Output is either:
// `stdout`, `stderr`, or `file`.
// `stdout`, `stderr`, or `file`
func WithOutputStr(output, file string) Option {
opt := func(*options) error { return nil }

Expand Down Expand Up @@ -129,15 +129,15 @@ func WithOutputStr(output, file string) Option {
return opt
}

// WithOutput configures the writer used to write logs to.
// WithOutput configures the writer used to write logs to
func WithOutput(writer io.Writer) Option {
return func(opt *options) error {
opt.logger.Out = writer
return nil
}
}

// WithSetReportCaller configures the logrus logger SetReportCaller.
// WithSetReportCaller configures the logrus logger SetReportCaller
func WithSetReportCaller(enable bool) Option {
return func(opt *options) error {
opt.logger.SetReportCaller(enable)
Expand Down
2 changes: 1 addition & 1 deletion internal/log/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var logger *logrus.Logger

// newLogger is a delegator method for logrus.New.
// newLogger is a delegator method for logrus.New
func newLogger() *logrus.Logger {
return logrus.New()
}
Loading

0 comments on commit c766146

Please sign in to comment.