diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 187b4ed5a0..95044b8294 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -86,6 +86,7 @@ class Db def cmd_workspace_help print_line "Usage:" print_line " workspace List workspaces" + print_line " workspace -v List workspaces verbosely" print_line " workspace [name] Switch workspace" print_line " workspace -a [name] ... Add workspace(s)" print_line " workspace -d [name] ... Delete workspace(s)" @@ -111,6 +112,8 @@ class Db delete_all = true when '-r','--rename' renaming = true + when '-v' + verbose = true else names ||= [] names << arg @@ -178,12 +181,21 @@ class Db end else workspace = framework.db.workspace + + unless verbose + framework.db.workspaces.each do |ws| + pad = (ws == workspace) ? '* ' : ' ' + print_line("#{pad}#{ws.name}") + end + return + end + col_names = %w{current name hosts services vulns creds loots notes} tbl = Rex::Text::Table.new( 'Header' => 'Workspaces', 'Columns' => col_names, - 'SortIndex' => 1 + 'SortIndex' => -1 ) # List workspaces diff --git a/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb b/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb index 9a52a4afad..4900729224 100644 --- a/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb +++ b/spec/lib/msf/ui/console/command_dispatcher/db_spec.rb @@ -542,9 +542,29 @@ RSpec.describe Msf::Ui::Console::CommandDispatcher::Db do db.cmd_workspace "-D" @output = [] end + describe "" do it "should list default workspace" do db.cmd_workspace + expect(@output).to match_array [ + "* default" + ] + end + + it "should list all workspaces" do + db.cmd_workspace("-a", "foo") + @output = [] + db.cmd_workspace + expect(@output).to match_array [ + " default", + "* foo" + ] + end + end + + describe "-v" do + it "should list default workspace verbosely" do + db.cmd_workspace("-v") expect(@output).to match_array [ "", "Workspaces", @@ -555,10 +575,10 @@ RSpec.describe Msf::Ui::Console::CommandDispatcher::Db do ] end - it "should list all workspaces" do + it "should list all workspaces verbosely" do db.cmd_workspace("-a", "foo") @output = [] - db.cmd_workspace + db.cmd_workspace("-v") expect(@output).to match_array [ "", "Workspaces", @@ -613,6 +633,7 @@ RSpec.describe Msf::Ui::Console::CommandDispatcher::Db do expect(@output).to match_array [ "Usage:", " workspace List workspaces", + " workspace -v List workspaces verbosely", " workspace [name] Switch workspace", " workspace -a [name] ... Add workspace(s)", " workspace -d [name] ... Delete workspace(s)",