Code Monkey home page Code Monkey logo

Comments (12)

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

May I implement this one ?

from gol.

yakuter avatar yakuter commented on August 28, 2024

Of course. It is on you @betelgeuse-7

from gol.

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

Thanks!

from gol.

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

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

from gol.

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

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

from gol.

yakuter avatar yakuter commented on August 28, 2024

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

from gol.

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

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.

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

You can deassign me

from gol.

yakuter avatar yakuter commented on August 28, 2024

@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.

yakuter avatar yakuter commented on August 28, 2024

Alright, I deassigned you.

from gol.

yakuter avatar yakuter commented on August 28, 2024

Closed by #18

from gol.

betelgeuse-7 avatar betelgeuse-7 commented on August 28, 2024

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

from gol.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.