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

whoami command #10

Closed
yakuter opened this issue Oct 20, 2022 · 12 comments
Closed

whoami command #10

yakuter opened this issue Oct 20, 2022 · 12 comments
Labels

Comments

@yakuter
Copy link
Owner

yakuter commented Oct 20, 2022

Get the active username command.

@abdrd
Copy link

abdrd commented Oct 20, 2022

May I implement this one ?

@yakuter
Copy link
Owner Author

yakuter commented Oct 20, 2022

Of course. It is on you @betelgeuse-7

@abdrd
Copy link

abdrd commented Oct 20, 2022

Thanks!

@abdrd
Copy link

abdrd commented Oct 20, 2022

Is it okay if I don't use github.com/urfave/cli/v2 package ?

@abdrd
Copy link

abdrd commented Oct 20, 2022

I am planning to implement other commands, and I don't like to use an abstraction for such small applications.

@yakuter
Copy link
Owner Author

yakuter commented Oct 20, 2022

Well this cli package is the skeleton of our CLI application "gol". So I expect you to implement this feature just like the echo command. You don't need abstraction. You can just duplicate the command architecture from other commands
Screen Shot 2022-10-20 at 16 49 33

@abdrd
Copy link

abdrd commented Oct 20, 2022

I had implemented it like this:

const (
	_HELP = `Usage: whoami [OPTION]
Print  the  user name associated with the current effective user ID.  
Same as id -un.

	--help, -h 		display this help and exit
	--version, -v 	output version information and exit		
`
	_VERSION = "0.0.1"
	_CMDNAME = "whoami"
)

func whoami(args []string) error {
	argsLen := len(args)
	switch argsLen {
	case 1:
		// only program name
		u, err := user.Current()
		if err != nil {
			return err
		}
		fmt.Println(u.Username)
	case 2:
		arg := args[1]
		switch arg {
		case "--help", "-h":
			fmt.Print(_HELP)
		case "--version", "-v":
			fmt.Printf("whoami - version %s\n", _VERSION)
		default:
			return fmt.Errorf("unknown command '%s'; pass '--help', or '-h' for help information", arg)
		}
	default:
		return fmt.Errorf("excessive number of arguments (%d)", argsLen)
	}
	return nil
}

func Run(args []string) error {
	return whoami(args)
}

/// TESTS

OK then... Good luck

@abdrd
Copy link

abdrd commented Oct 20, 2022

You can deassign me

@yakuter
Copy link
Owner Author

yakuter commented Oct 20, 2022

@betelgeuse-7 I would like you to complete the PR if it is OK with you. You could have just used the lines you wrote with a command template like echo here

u, err := user.Current()
if err != nil {
	return err
}
fmt.Println(u.Username)

@yakuter
Copy link
Owner Author

yakuter commented Oct 20, 2022

Alright, I deassigned you.

@yakuter
Copy link
Owner Author

yakuter commented Oct 20, 2022

Closed by #18

@yakuter yakuter closed this as completed Oct 20, 2022
@abdrd
Copy link

abdrd commented Oct 21, 2022

Sorry for wasting your time. I hopped into this without actually reading the code-base.
Again, sorry...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants