{"id":1780,"date":"2010-09-19T19:11:28","date_gmt":"2010-09-19T18:11:28","guid":{"rendered":"http:\/\/www.devco.net\/?p=1780"},"modified":"2010-09-19T19:11:28","modified_gmt":"2010-09-19T18:11:28","slug":"having_fun_with_irb","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2010\/09\/19\/having_fun_with_irb.php","title":{"rendered":"Having fun with IRB"},"content":{"rendered":"

I’ve had a pipe dream of creating something like IRB for ruby but tailored for mcollective, something with DDL assisted completion and all sorts of crazy kewl things.<\/p>\n

Having looked a few times into this I concluded IRB is a black box of undocumented voodoo and always gave up. I had another google this weekend and came across what set me off in the right direction. <\/p>\n

Christopher Burnett<\/a> has a great little Posterous post up showing how to build custom IRB shells<\/a>. With a little further digging I came across Bond<\/a> from Gabriel Horner<\/a>. These two combined into something that will definitely be one of my favorite toys.<\/p>\n

The result is a mcollective IRB shell that you can grab in the ext directory<\/a> of the mcollective tarball – it brings in some native gem dependencies that I really don’t want in the base deploy.<\/p>\n

It’s best to see it in action before looking at the code so you know what the behavior is, see the screen cast below.<\/p>\n

<\/embed><\/p>\n

Getting the basic mc-irb going was pretty much exactly as Christopher’s posterous shows so I won’t go into the detail of that, what I do want to show is the DDL based command completion with Bond. <\/p>\n

<\/p>\n

\r\n        require 'bond'\r\n        Bond.start\r\n\r\n        Bond.complete(:method => \"rpc\") do |e|\r\n            begin\r\n                if e.argument == 1\r\n                    if e.arguments.last == \"?\"\r\n                        puts \"\\n\\nActions for #{@agent_name}:\\n\"\r\n\r\n                        @agent.ddl.actions.each do |action|\r\n                           puts \"%20s - %s\" % [ \":#{action}\", @agent.ddl.action_interface(action)[:description] ] \r\n                        end\r\n\r\n                        print \"\\n\" + e.line\r\n                    end\r\n\r\n                    @agent.ddl.actions\r\n\r\n                elsif e.argument > 1\r\n                    action = eval(e.arguments[0]).to_s\r\n                    ddl = @agent.ddl.action_interface(action)\r\n\r\n                    if e.arguments.last == \"?\"\r\n                        puts \"\\n\\nArguments for #{action}:\\n\"\r\n                        ddl[:input].keys.each do |input|\r\n                            puts \"%20s - %s\" % [ \":#{input}\", ddl[:input][input][:description] ]\r\n                        end\r\n\r\n                        print \"\\n\" + e.line\r\n                    end\r\n\r\n                    ddl[:input].keys\r\n                end\r\n            rescue Exception \r\n                []\r\n            end\r\n        end\r\n<\/pre>\n

<\/code><\/p>\n

This code checks the argument count, handles the first and subsequent arguments differently and supports the ?<\/em> special case by loading the DDL and displaying the right stuff. <\/p>\n

I’ve not found much by way of complex examples on the Bond site or its own bundled completions, hopefully this helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"

I’ve had a pipe dream of creating something like IRB for ruby but tailored for mcollective, something with DDL assisted completion and all sorts of crazy kewl things. Having looked a few times into this I concluded IRB is a black box of undocumented voodoo and always gave up. I had another google this weekend […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[1],"tags":[121,78,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1780"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1780"}],"version-history":[{"count":3,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1780\/revisions"}],"predecessor-version":[{"id":1783,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1780\/revisions\/1783"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}