consular icon indicating copy to clipboard operation
consular copied to clipboard

DOCUMENTATION: how to use dynamically?

Open lastobelus opened this issue 12 years ago • 3 comments

I'm confused about how to go about using consular dynamically.

For example, say I have some command that returns a list of nodes in a cluster with their ip address. The number of nodes can vary, and the ip addresses are dynamic. How would I use consular to open a tab for each node and ssh to the node's ip address?

lastobelus avatar Jul 24 '12 21:07 lastobelus

The consular script are just ruby scripts with the consular DSL available to them. A simple example:


class Foo
  def self.ips
    %w{foo bar fizz buzz}
  end
end

Foo.ips.each do |word|
  tab "echo #{word}"
end

achiurizo avatar Jul 24 '12 21:07 achiurizo

I guess I didn't make myself entirely clear. What I mean is, how would I use consular dynamically in some generic script, without creating a project file? What would I have to do to use the above class without going through bin/consular?

lastobelus avatar Jul 24 '12 22:07 lastobelus

I'd suggest taking a look at the other consular cores source. The cores are the main entry point into the execution of the commands and takes a hash that's being generated by Consular::DSL. To be frank, I didn't think about using it outside of the CLI. So their are some caveats with this, namely the DSL expects a file to load to generate the appropriate hash. You could do things.

  • Generate the hash manually and load it into the core. You can look at the Consular::DSL class or its spec to see how its built.
  • Pass in an empty file and manually invoke the dsl methods on the DSL instance, and generate the hash via Consular::DSL#to_hash and pass that into the desired core.

I hope this helps, I'll probably need to rework this a bit in the future as this use case those make sense.

achiurizo avatar Jul 25 '12 17:07 achiurizo