5 ms·
Hk, The new Heroku Client written in Go
- neya 13y agoOn 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..
- pestaa 13y ago1. 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.
- iand 13y agoAre 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 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.
- neya 13y agoThanks for the link to the source, I was asking in general though.
- iand 13y agoPrinciple 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_process_argv http://nodejs.org/docs/latest/api/process.html#process_proce... python - http://docs.python.org/2/library/sys.html http://docs.python.org/2/library/sys.html ruby - http://www.ruby-doc.org/core-2.0.0/ARGF.html#method-i-argv http://www.ruby-doc.org/core-2.0.0/ARGF.html#method-i-argv
- deleted 13y ago[deleted]
- neya 13y agoExcellent! Thank you very much :)
- chimeracoder 13y agoYou're looking for the "flag" package, in the standard library: http://golang.org/pkg/flag/ http://golang.org/pkg/flag/
- dscrd 13y agoPerhaps check if this is good enough for you https://github.com/robmerrell/comandante https://github.com/robmerrell/comandante
- neya 13y agoThanks, this is excellent for a Go implementation. And I will definitely use it! I was asking in general though..
- walle_ 13y agoDo 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 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.
- oblio 13y agoFrankly, this is how command line interfaces should be created: https://github.com/docopt/docopt https://github.com/docopt/docopt If only it would be ported to more languages...
- knocte 13y agoLast time I looked at heroku, I had to install some non-open-source command-line tools to interact with it. So I'm wondering, is this alternative opensource now?
- miloshadzic 13y agoThis is the kind of thing that Go shines at.
- zimbatm 13y agoHeroku is going to loose Solaris and a couple of other secondary target OSes if they go down that route. Golang can cross-compile to Linux, Darwin, Windows and a couple of BSDs. EDIT: It really seems that they are going down that route. They are also working on a Go implementation of Foreman here: https://github.com/ddollar/forego https://github.com/ddollar/forego
- ithkuil 13y agohk cannot be compiled with gccgo?
- enneff 13y agoI wonder if they have any customers that use Solaris.
- axaxs 13y agoGc, the reference implementation, only does the mentioned OSes. Gccgo should work where gcc is available, and is known to work on Solaris. See - http://blog.golang.org/gccgo-in-gcc-471 http://blog.golang.org/gccgo-in-gcc-471
- 4ad 13y agoI am working on a Solaris (illumos rather) port of the gc toolchain. It's halfway there: https://bitbucket.org/4ad/go-sunos https://bitbucket.org/4ad/go-sunos
- iand 13y agoJust do go build -compiler gccgo hk to build using GCC
- 4ad 13y agoYou have to manually compile the go tool though, as it doesn't come with gccgo.
- pearkes 13y agoI use the two Heroku tools `foreman` and `heroku` regularly. I've recently switched to their Go alternatives, and for one thing, the speed has improved[1]. However, the Heroku client is mostly network bound (communicating with their API), and on an average connection this speedup hardly matters. I wonder what the other benefits will be? [1] $ time heroku help real 0m0.409s user 0m0.146s sys 0m0.036s $ time hk help real 0m0.008s user 0m0.003s sys 0m0.004s $ time foreman run echo hello real 0m2.062s user 0m0.199s sys 0m0.100s $ time forego run echo hello real 0m0.886s user 0m0.205s sys 0m0.097s
- mitchellh 13y agoThe benefit would be EASY cross platform support. From experience building Vagrant installers: it's a pain in the butt. Shipping a single binary client would probably simplify things greatly.
- ddollar 13y agoThere are two reasons I rewrote Foreman in Go. You hit one of them square on the head. A single binary with no dependencies that can be cross-compiled on a Heroku dyno makes things much simpler. Foreman was originally written in Ruby which ideally means it runs on any machine with a Ruby interpreter. When you get down to it, though, the differences in fork/exec between Ruby 1.8, 1.9, JRuby, Rubinius, etc make this a nightmare scenario of a different sort. If you go to https://gobuild.herokuapp.com/ddollar/forego/master/darwin/amd64 https://gobuild.herokuapp.com/ddollar/forego/master/darwin/a... you get a working program as a single binary in one step. Using bsdiff I can even ship binary diffs for fast upgrades (this is how `foreman update` works in the new version) Oh and as a side effect the new Foreman is quite a lot faster to start up (Rubygems initialization is sloooooow)
- warmwaffles 13y agoI had no clue `forego` was actually available. This is incredible.
- kungfooguru 13y ago
- fderp 13y agoUsing the heroku client every day, I noticed this new client does not namespace any of the commands. Subcommands of hk are: hk create # create app hk destroy # destroy app hk apps # list apps hk set # set config var hk unset #unset config var Compare to heroku's (preferable, imho) commands: heroku apps:create # create app heroku apps:destroy # destroy app heroku apps # list apps heroku config:set # set config var heroku config:unset # unset config var The command 'hk set' doesn't tell you any semantic information at all about what it's doing - I prefer the original syntax for its convention of being explicit. Other than that minor complaint, seems like a really cool project, going to look through the source later.
- bgentry 13y agoThe commands right now attempt to map directly to unix equivalents where it makes sense. set, unset, & env are the traditional unix commands for modifying the environment. The main problem I have with the flat, non-namespaced commands is that there will be far too many of them once we've implemented the full command set. Anyway, as I wrote in my other comment, this is very early software and it has a long way to go before I'll recommend that regular Heroku users rely on it.
- bgentry 13y agoHi everyone, I'm the new maintainer of hk. It's actually not very new :) You can see that Keith Rarick did most of the work on it over a year ago, along with some other major contributors: https://github.com/heroku/hk/graphs/contributors https://github.com/heroku/hk/graphs/contributors What is new is that I moved it to the Heroku org this week and will be spending a lot of my time turning it into a proper replacement for the Heroku Toolbelt & gem. It's still very early stage software, though. There isn't currently a supported installation method, and it's very far from having all of the necessary features to fully replace the old client. Also, the UX will probably change frequently and things may break, eat your data, etc. So don't rely on it just yet :) That being said, I'm really excited to see where we can take this in the next few months. Hk is already a great starting point. Go is very fast and lightweight, and offers some nice advantages over Ruby on the distribution & installation fronts. Hopefully we'll have something exciting to show in a couple months!
- FLUX-YOU 13y ago$ hk 47 Statement: Greetings, meatbag