Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds custom user name option #91

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/spf13/cobra"
)

var userName string

var root = &cobra.Command{
Use: "slides <file.md>",
Short: "Slides is a terminal based presentation tool",
Expand All @@ -24,14 +26,17 @@ var root = &cobra.Command{
fileName = args[0]
}

user, err := user.Current()
if err != nil {
return errors.New("could not get current user")
if userName == "" {
user, err := user.Current()
if err != nil {
return errors.New("could not get current user")
}
userName = user.Name
}

presentation := model.Model{
Page: 0,
Author: user.Name,
Author: userName,
Date: time.Now().Format("2006-01-02"),
FileName: fileName,
}
Expand All @@ -47,8 +52,8 @@ var root = &cobra.Command{
}

func Execute() {
err := root.Execute()
if err != nil {
root.Flags().StringVarP(&userName, "username", "u", "", "Custom user name to show in the footer")
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
Expand Down