diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-11-05 19:21:19 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-11-05 19:21:19 +0530 |
commit | c29b8da2b0353bb5d6e499b5d7cc79c0fadab9b3 (patch) | |
tree | d61162809902543dc8d21c07c77387e7c48781d7 | |
parent | 81d22f6e8cd95254a272d8b303f0b6427b3bc888 (diff) | |
download | chef-c29b8da2b0353bb5d6e499b5d7cc79c0fadab9b3.tar.gz |
Validate name argument for knife list
- Add required specs.
- Raise an error if no argument provided.
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
-rw-r--r-- | lib/chef/knife/list.rb | 9 | ||||
-rw-r--r-- | spec/integration/knife/list_spec.rb | 18 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/chef/knife/list.rb b/lib/chef/knife/list.rb index e5e196ecea..03e8cf199c 100644 --- a/lib/chef/knife/list.rb +++ b/lib/chef/knife/list.rb @@ -62,10 +62,15 @@ class Chef attr_accessor :exit_code def run - patterns = name_args.length == 0 ? [""] : name_args + + if name_args.length == 0 + show_usage + ui.fatal("You must specify at least one argument. If you want to list everything in this directory, run \"knife list .\"") + exit 1 + end # Get the top-level matches - all_results = parallelize(pattern_args_from(patterns)) do |pattern| + all_results = parallelize(pattern_args_from(name_args)) do |pattern| pattern_results = Chef::ChefFS::FileSystem.list(config[:local] ? local_fs : chef_fs, pattern).to_a if pattern_results.first && !pattern_results.first.exists? && pattern.exact_path diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index 830dd0e428..c213ef77c4 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -316,8 +316,12 @@ describe "knife list", :workstation do context "when cwd is at the top of the repository" do before { cwd "." } + it "knife list with no parameters reports an error" do + knife("list").should_fail "FATAL: You must specify at least one argument. If you want to list everything in this directory, run \"knife list .\"\n", stdout: /USAGE/ + end + it "knife list -Rfp returns everything" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM clients/ clients/chef-validator.json clients/chef-webui.json @@ -438,7 +442,7 @@ describe "knife list", :workstation do end it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -457,7 +461,7 @@ describe "knife list", :workstation do before { cwd "cookbooks/cookbook2" } it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM metadata.rb recipes/ recipes/default.rb @@ -476,7 +480,7 @@ describe "knife list", :workstation do before { cwd "cookbooks" } it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -491,7 +495,7 @@ describe "knife list", :workstation do before { cwd "symlinked" } it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -513,7 +517,7 @@ describe "knife list", :workstation do before { cwd "real_cookbooks" } it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM cookbook1/ cookbook1/metadata.rb cookbook2/ @@ -528,7 +532,7 @@ describe "knife list", :workstation do before { cwd "cookbooks" } it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM + knife("list -Rfp .").should_succeed <<~EOM cookbook1/ cookbook1/metadata.rb cookbook2/ |