-
Notifications
You must be signed in to change notification settings - Fork 15
add extra CLI commands to syskit #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,91 @@ def orogen_test(*args) | |
| "commands related to monitoring and commanding a running Syskit system" | ||
| subcommand "telemetry", Telemetry::CLI | ||
|
|
||
| desc "bundle_dir NAME", "print the directory of a bundle" | ||
| def bundle_dir(name) | ||
| require "rock/bundle" unless defined?(Rock::Bundles) | ||
|
|
||
| bundle = Rock::Bundles.each_bundle.find { |b| b.name == name } | ||
| if bundle | ||
| puts bundle.path | ||
| else | ||
| $stderr.puts "No bundle named '#{name}' found." | ||
| $stderr.puts "Available bundles are: #{Rock::Bundles.each_bundle.map(&:name).sort.join(', ')}" | ||
| exit 1 | ||
| end | ||
| end | ||
|
|
||
| desc "config ROBOT", "print the configuration of a given robot" | ||
| option :key, type: :string, repeatable: true, default: [] | ||
| option :from_bundle, type: :string, default: nil | ||
| def config(robot_name) | ||
|
Comment on lines
+58
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically, syskit is ran from the bundle itself. Besides that, I think a more useful command would to extract the variables inside the I dont think that what you aimed for here should be packed with syskit, it can mostly be resolved by using a sequence of bash commands, and it is outside of syskit's scope
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I could also that, but I believe it should be a distinct command from this one. The current proposed
Yes, but for the templated SDF generation use case we dont run |
||
| require "yaml" | ||
|
|
||
| if (from_bundle = options[:from_bundle]) | ||
| require "rock/bundle" unless defined?(Rock::Bundles) | ||
|
|
||
| bundle = Rock::Bundles.each_bundle.find { |b| b.name == from_bundle } | ||
| if bundle | ||
| Dir.chdir(bundle.path) | ||
| else | ||
| $stderr.puts "No bundle named '#{from_bundle}' found." | ||
| $stderr.puts "Available bundles are: #{Rock::Bundles.each_bundle.map(&:name).sort.join(', ')}" | ||
| exit 1 | ||
| end | ||
| end | ||
|
|
||
| app = Roby.app | ||
| app.require_app_dir | ||
| app.load_config_yaml | ||
| app.setup_robot_names_from_config_dir | ||
| app.robot(robot_name) | ||
|
|
||
| merger = proc do |_, old_val, new_val| | ||
| if old_val.is_a?(Hash) && new_val.is_a?(Hash) | ||
| old_val.merge(new_val, &merger) | ||
| elsif old_val.is_a?(Array) && new_val.is_a?(Array) | ||
| old_val + new_val | ||
| else | ||
| new_val | ||
| end | ||
| end | ||
|
|
||
| config_path = ["config", "robots", "ROBOT.yml"] | ||
| merged_hash = app.find_files( | ||
| *config_path, all: true, order: :specific_last | ||
| ).each_with_object({}) do |path, config_hash| | ||
| values = YAML.safe_load(File.read(path)) || {} | ||
| config_hash.merge!(values, &merger) | ||
| end | ||
|
|
||
| if options[:key].empty? | ||
| result = merged_hash | ||
| else | ||
| resolved_queries = options[:key].map do |key_query| | ||
| keys = key_query.split(".") | ||
| parent = keys.size > 1 ? merged_hash.dig(*keys[0...-1]) : merged_hash | ||
|
|
||
| unless parent.is_a?(Hash) && parent.has_key?(keys.last) | ||
| $stderr.puts "Error: Key '#{key_query}' not found." | ||
| exit 1 | ||
| end | ||
|
|
||
| [keys, merged_hash.dig(*keys)] | ||
| end | ||
|
|
||
| if resolved_queries.size == 1 | ||
| result = resolved_queries.first.last | ||
| else | ||
| result = resolved_queries.reduce({}) do |accum, (keys, value)| | ||
| nested_path_hash = keys.reverse.reduce(value) { |v, k| { k => v } } | ||
| accum.merge(nested_path_hash, &merger) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| puts YAML.dump(result) | ||
| end | ||
|
|
||
| no_commands do | ||
| def setup_interface(*, **) | ||
| interface_version = options[:interface_version] || 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This possibly exists in autoproj, or at least it is possible to get this information from an autoproj command (ie autoproj show bundles/bla)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you can find packages with
autoproj locate PACKAGE_NAMEor withautoproj show PACKAGE_NAMEas you said. But IMO it can be helpful to have this extra command, it is simple, easy to remember, and doesn't require autoproj. On the other hand, it doesn't bring any disadvantages