News for hackers. Stuff that matters.
Re:Hk, The new Heroku Client written in Go by neya on Wednesday October 23, 2013 @05:46AM (#6597791)
On a side note, I would like someone with experience here to tell me how you can actually create command line commands? In this case, they seem to use:

    hk <insert command here>
I would like to do something like:

   abc <some command>
Basically something like a Rails scaffold generator. How difficult/easy is this? Googling didn't help much..

Note: It doesn't have to be built with Golang..

Thanks

Edit: Thanks for the replies :)

Note: It doesn't have to be just Go, I'm just asking in general..

I would basically like to create a scaffold generator. So, when I do

    abc generate test
I would like a file named test.html (or something) generated..

Thanks again..

Re:Hk, The new Heroku Client written in Go by dscrd on Wednesday October 23, 2013 @06:24AM (#6597894)
Perhaps check if this is good enough for you https://github.com/robmerrell/comandante
Re:Hk, The new Heroku Client written in Go by neya on Wednesday October 23, 2013 @06:35AM (#6597921)
Thanks, this is excellent for a Go implementation. And I will definitely use it! I was asking in general though..
Re:Hk, The new Heroku Client written in Go by iand on Wednesday October 23, 2013 @06:12AM (#6597860)
Are you asking how to do this in Go or how to do it in general?

Here's how the hk app does it: https://github.com/heroku/hk/blob/master/main.go#L120

Basically it reads the arguments to the executable and matches them against a built-in list of supported commands and dispatches appropriately.

Re:Hk, The new Heroku Client written in Go by neya on Wednesday October 23, 2013 @06:33AM (#6597915)
Thanks for the link to the source, I was asking in general though.
Re:Hk, The new Heroku Client written in Go by iand on Wednesday October 23, 2013 @06:37AM (#6597930)
Principle is the same in any language. They all provide a way to parse the arguments passed in. You need to examine those and call the right code based on the argument name. Look for something called ARGV or similar in your language. For example:

node.js - http://nodejs.org/docs/latest/api/process.html#process_proce...

python - http://docs.python.org/2/library/sys.html

ruby - http://www.ruby-doc.org/core-2.0.0/ARGF.html#method-i-argv

Re:Hk, The new Heroku Client written in Go by chimeracoder on Wednesday October 23, 2013 @09:25AM (#6598523)
You're looking for the "flag" package, in the standard library: http://golang.org/pkg/flag/
Re:Hk, The new Heroku Client written in Go by walle_ on Wednesday October 23, 2013 @06:38AM (#6597932)
Do you mean how to do plugins for your application?

I use this route in one of my projects https://github.com/walle/gas/blob/development/bin/gas

Basically, all executables in your PATH that conforms to a naming convention is a plugin. If a match is found it's run.

So in my case you can call both ´$ gas list´ and ´$ gas-list´.

I don't know if this is the best way to do it, my inspiration was how git commands work.

Re:Hk, The new Heroku Client written in Go by pestaa on Wednesday October 23, 2013 @06:10AM (#6597858)
1. Make an executable.

2. Put it in your PATH.

3. Profit.

The long version is more complicated than that, but you need to tell more details first.

Re:Hk, The new Heroku Client written in Go by oblio on Wednesday October 23, 2013 @02:05PM (#6600502)
Frankly, this is how command line interfaces should be created: https://github.com/docopt/docopt

If only it would be ported to more languages...