Skip to content

Commit

Permalink
feat: update tutorial command
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Dec 5, 2023
1 parent 1edc95b commit 4ca2a7f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 51 deletions.
16 changes: 16 additions & 0 deletions cli/cmd/utility/tutorial.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@ var TutorialCmd = common.NewDiveCommandBuilder().

func tutorial(cmd *cobra.Command, args []string) {

cli := common.GetCli()

cli.Logger().SetOutputToStdout()

err := common.ValidateArgs(args)

if err != nil {
cli.Logger().Error(common.CodeOf(err), common.Errorcf(common.CodeOf(err), "error %s !!! \n%s", err, cmd.UsageString()).Error())
}

cli.Logger().Info("Redirecting to YouTube.....")

if err := common.OpenFile(tutorialURL); err != nil {
cli.Logger().Fatalf(common.InvalidCommandError, common.Errorcf(common.CodeOf(err), "Failed to open Dive YouTube chanel with error %v", err).Error())
}

}
10 changes: 5 additions & 5 deletions cli/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Logger interface {
Warn(message string)
Error(errorCode ErrorCode, errorMessage string)
Fatal(errorCode ErrorCode, errorMessage string)
Infof(message string)
Warnf(message string)
Debugf(message string)
Errorf(errorCode ErrorCode, errorMessage string)
Fatalf(errorCode ErrorCode, errorMessage string)
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Debugf(format string, args ...interface{})
Errorf(errorCode ErrorCode, format string, args ...interface{})
Fatalf(errorCode ErrorCode, format string, args ...interface{})
}

type Spinner interface {
Expand Down
72 changes: 26 additions & 46 deletions cli/common/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewDiveLogger(infoFilePath string, errorFilePath string) *diveLogger {
})

ditLogger := &lumberjack.Logger{
// Log file abbsolute path, os agnostic
// Log file absolute path, os agnostic
Filename: filepath.ToSlash(infoFilePath),
LocalTime: true,
}
Expand Down Expand Up @@ -66,69 +66,49 @@ func (d *diveLogger) SetErrorToStderr() {
func (d *diveLogger) SetOutputToStdout() {
d.log.SetOutput(os.Stdout)
}
func (d *diveLogger) Debug(message string) {

d.log.WithFields(logrus.Fields{
"level": "🐞 debug",
}).Debug(message)

func (d *diveLogger) logWithFields(level logrus.Level, kind string, format string, args ...interface{}) {
if d.log.IsLevelEnabled(level) {
d.log.WithFields(logrus.Fields{"kind": kind}).Logf(level, format, args...)
}
}
func (d *diveLogger) Info(message string) {
d.log.WithFields(logrus.Fields{
"level": "ℹ️ info",
}).Info(message)

func (d *diveLogger) Debug(message string) {
d.logWithFields(logrus.DebugLevel, "🐞 debug", message)
}
func (d *diveLogger) Warn(message string) {
d.log.WithFields(logrus.Fields{
"level": "⚠️ warn",
}).Warn(message)

func (d *diveLogger) Info(message string) {
d.logWithFields(logrus.InfoLevel, "ℹ️ info", message)
}
func (d *diveLogger) Error(errorCode ErrorCode, errorMessage string) {
d.log.WithFields(logrus.Fields{
"level": "🛑 error",
"error_code": errorCode,
}).Error(errorMessage)

func (d *diveLogger) Warn(message string) {
d.logWithFields(logrus.WarnLevel, "⚠️ warn", message)
}
func (d *diveLogger) Fatal(errorCode ErrorCode, errorMessage string) {
d.log.WithFields(logrus.Fields{
"level": "💀 fatal",
"error_code": errorCode,
}).Fatal(errorMessage)

func (d *diveLogger) Error(errorCode ErrorCode, errorMessage string) {
d.logWithFields(logrus.ErrorLevel, "🛑 error", "%s", errorMessage)
}
func (d *diveLogger) Infof(message string) {
d.log.WithFields(logrus.Fields{
"level": "ℹ️ info",
}).Infof("%s", message)

func (d *diveLogger) Fatal(errorCode ErrorCode, errorMessage string) {
d.logWithFields(logrus.FatalLevel, "💀 fatal", "%s", errorMessage)
}
func (d *diveLogger) Warnf(message string) {
d.log.WithFields(logrus.Fields{
"level": "⚠️ warn",
}).Warnf("%s", message)

func (d *diveLogger) Infof(format string, args ...interface{}) {
d.logWithFields(logrus.InfoLevel, "ℹ️ info", format, args...)
}
func (d *diveLogger) Debugf(message string) {

d.log.WithFields(logrus.Fields{
"level": "🐞 debug",
}).Debugf("%s", message)
func (d *diveLogger) Warnf(format string, args ...interface{}) {
d.logWithFields(logrus.WarnLevel, "⚠️ warn", format, args...)
}

func (d *diveLogger) Debugf(format string, args ...interface{}) {
d.logWithFields(logrus.DebugLevel, "🐞 debug", format, args...)
}
func (d *diveLogger) Errorf(errorCode ErrorCode, errorMessage string) {
d.log.WithFields(logrus.Fields{
"level": "🛑 error",
"error_code": errorCode,
}).Errorf("%s", errorMessage)

func (d *diveLogger) Errorf(errorCode ErrorCode, format string, args ...interface{}) {
d.logWithFields(logrus.ErrorLevel, "🛑 error", format, args...)
}
func (d *diveLogger) Fatalf(errorCode ErrorCode, errorMessage string) {
d.log.WithFields(logrus.Fields{
"level": "💀 fatal",
"error_code": errorCode,
}).Fatalf("%s", errorMessage)

func (d *diveLogger) Fatalf(errorCode ErrorCode, format string, args ...interface{}) {
d.logWithFields(logrus.FatalLevel, "💀 fatal", format, args...)
}

0 comments on commit 4ca2a7f

Please sign in to comment.