Comments (12)
May I implement this one ?
from gol.
Of course. It is on you @betelgeuse-7
from gol.
Thanks!
from gol.
Is it okay if I don't use github.com/urfave/cli/v2
package ?
from gol.
I am planning to implement other commands, and I don't like to use an abstraction for such small applications.
from gol.
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
from gol.
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
from gol.
You can deassign me
from gol.
@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)
from gol.
Alright, I deassigned you.
from gol.
Closed by #18
from gol.
Sorry for wasting your time. I hopped into this without actually reading the code-base.
Again, sorry...
from gol.
Related Issues (13)
- ls command HOT 3
- README file is needed. HOT 2
- grep command HOT 2
- pwd command
- Curl HOT 2
- mkdir command
- mv command HOT 2
- cp command HOT 3
- rm command HOT 2
- touch command HOT 2
- cat command HOT 2
- uname command HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gol.