From 5b2f02086f9295cf16e19cb3b7e5369b313bb422 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 12 Nov 2020 14:21:26 +0300 Subject: Add --all-pattern option to pkg-{update,clean,test,install,uninstall} commands --- bpkg/pkg-clean.cli | 23 +++++++++++++++++------ bpkg/pkg-clean.hxx | 1 + bpkg/pkg-command.cxx | 29 ++++++++++++++++++++++++++--- bpkg/pkg-command.hxx | 1 + bpkg/pkg-install.cli | 27 +++++++++++++++++++-------- bpkg/pkg-install.hxx | 1 + bpkg/pkg-test.cli | 22 ++++++++++++++++------ bpkg/pkg-test.hxx | 1 + bpkg/pkg-uninstall.cli | 26 ++++++++++++++++++-------- bpkg/pkg-uninstall.hxx | 1 + bpkg/pkg-update.cli | 24 +++++++++++++++++------- bpkg/pkg-update.hxx | 1 + tests/pkg-test.testscript | 37 +++++++++++++++++++++++++++++++++++++ 13 files changed, 156 insertions(+), 38 deletions(-) diff --git a/bpkg/pkg-clean.cli b/bpkg/pkg-clean.cli index b4cb05f..d51736a 100644 --- a/bpkg/pkg-clean.cli +++ b/bpkg/pkg-clean.cli @@ -15,15 +15,18 @@ namespace bpkg "\h|SYNOPSIS| \c{\b{bpkg pkg-clean}|\b{clean} [] [] ...\n - \b{bpkg pkg-clean}|\b{clean} [] [] \b{--all}|\b{-a}} + \b{bpkg pkg-clean}|\b{clean} [] [] \b{--all}|\b{-a}\n + \b{bpkg pkg-clean}|\b{clean} [] [] (\b{--all-pattern} )...} \h|DESCRIPTION| - The \cb{pkg-clean} command cleans the specified packages (the first form) - or all the held packages (the second form, see \l{bpkg-pkg-status(1)}). - Underneath, this command doesn't do much more than run \cb{b clean}. In - the first form the specified packages must have been previously - configured with \l{bpkg-pkg-build(1)} or \l{bpkg-pkg-configure(1)}. + The \cb{pkg-clean} command cleans the specified packages (the first + form), all the held packages (the second form, see + \l{bpkg-pkg-status(1)}), or all the held packages that match any of the + specified wildcard patterns (the third form). Underneath, this command + doesn't do much more than run \cb{b clean}. In the first form the + specified packages must have been previously configured with + \l{bpkg-pkg-build(1)} or \l{bpkg-pkg-configure(1)}. Additional command line variables (, normally \cb{config.*}) can be passed to the build system. Such variables apply to all the specified @@ -40,6 +43,14 @@ namespace bpkg { "Clean all held packages." } + + strings --all-pattern + { + "", + "Clean held packages that match the specified wildcard pattern. Repeat + this option to match multiple patterns. Note that you may need to + quote the pattern to prevent expansion by your shell." + } }; " diff --git a/bpkg/pkg-clean.hxx b/bpkg/pkg-clean.hxx index d99cd2a..c7c722c 100644 --- a/bpkg/pkg-clean.hxx +++ b/bpkg/pkg-clean.hxx @@ -21,6 +21,7 @@ namespace bpkg false /* recursive */, false /* immediate */, o.all (), + o.all_pattern (), false /* package_cwd */, args); } diff --git a/bpkg/pkg-command.cxx b/bpkg/pkg-command.cxx index 0828118..11f10f0 100644 --- a/bpkg/pkg-command.cxx +++ b/bpkg/pkg-command.cxx @@ -3,6 +3,8 @@ #include +#include + #include #include #include @@ -150,6 +152,7 @@ namespace bpkg bool recursive, bool immediate, bool all, + const strings& all_patterns, bool package_cwd, cli::group_scanner& args) { @@ -216,7 +219,7 @@ namespace bpkg // Check that options and arguments are consistent. // // Note that we can as well count on the option names that correspond to - // the immediate, recursive, and all parameters. + // the immediate, recursive, all, and all_patterns parameters. // { diag_record dr; @@ -225,9 +228,17 @@ namespace bpkg dr << fail << "both --immediate|-i and --recursive|-r specified"; else if (all) { + if (!all_patterns.empty ()) + dr << fail << "both --all|-a and --all-pattern specified"; + if (!pkg_args.empty ()) dr << fail << "both --all|-a and package argument specified"; } + else if (!all_patterns.empty ()) + { + if (!pkg_args.empty ()) + dr << fail << "both --all-pattern and package argument specified"; + } else if (pkg_args.empty ()) dr << fail << "package name argument expected"; @@ -257,7 +268,7 @@ namespace bpkg collect_dependencies (p, recursive, package_cwd, ps); }; - if (all) + if (all || !all_patterns.empty ()) { using query = query; @@ -270,7 +281,19 @@ namespace bpkg { l4 ([&]{trace << *p;}); - add (p, strings ()); + if (!all_patterns.empty ()) + { + for (const string& pat: all_patterns) + { + if (path_match (p->name.string (), pat)) + { + add (p, strings ()); + break; + } + } + } + else // --all + add (p, strings ()); } if (ps.empty ()) diff --git a/bpkg/pkg-command.hxx b/bpkg/pkg-command.hxx index 3196bb1..40a55f2 100644 --- a/bpkg/pkg-command.hxx +++ b/bpkg/pkg-command.hxx @@ -27,6 +27,7 @@ namespace bpkg bool recursive, bool immediate, bool all, + const strings& all_patterns, bool package_cwd, cli::group_scanner& args); diff --git a/bpkg/pkg-install.cli b/bpkg/pkg-install.cli index 308945a..ed22e3a 100644 --- a/bpkg/pkg-install.cli +++ b/bpkg/pkg-install.cli @@ -15,18 +15,21 @@ namespace bpkg "\h|SYNOPSIS| \c{\b{bpkg pkg-install}|\b{install} [] [] ...\n - \b{bpkg pkg-install}|\b{install} [] [] \b{--all}|\b{-a}} + \b{bpkg pkg-install}|\b{install} [] [] \b{--all}|\b{-a}\n + \b{bpkg pkg-install}|\b{install} [] [] (\b{--all-pattern} )...} \h|DESCRIPTION| The \cb{pkg-install} command installs the specified packages (the first - form) or all held packages (the second form, see \l{bpkg-pkg-status(1)}). - Additionally, immediate or all dependencies of these packages can be also - installed by specifying the \c{\b{--immediate}|\b{-i}} or - \c{\b{--recursive}|\b{-r}} options, respectively. Underneath, this - command doesn't do much more than run \cb{b install}. In the first form - the specified packages must have been previously configured with - \l{bpkg-pkg-build(1)} or \l{bpkg-pkg-configure(1)}. + form), all the held packages (the second form, see + \l{bpkg-pkg-status(1)}), or all the held packages that match any of the + specified wildcard patterns (the third form). Additionally, immediate or + all dependencies of these packages can be also installed by specifying + the \c{\b{--immediate}|\b{-i}} or \c{\b{--recursive}|\b{-r}} options, + respectively. Underneath, this command doesn't do much more than run + \cb{b install}. In the first form the specified packages must have been + previously configured with \l{bpkg-pkg-build(1)} or + \l{bpkg-pkg-configure(1)}. Additional command line variables (, normally \cb{config.*}) can be passed to the build system. Such variables apply to all the specified @@ -54,6 +57,14 @@ namespace bpkg "Install all held packages." } + strings --all-pattern + { + "", + "Install held packages that match the specified wildcard pattern. Repeat + this option to match multiple patterns. Note that you may need to quote + the pattern to prevent expansion by your shell." + } + bool --immediate|-i { "Also install immediate dependencies." diff --git a/bpkg/pkg-install.hxx b/bpkg/pkg-install.hxx index 5c06690..120576a 100644 --- a/bpkg/pkg-install.hxx +++ b/bpkg/pkg-install.hxx @@ -22,6 +22,7 @@ namespace bpkg o.recursive (), o.immediate (), o.all (), + o.all_pattern (), false /* package_cwd */, args); } diff --git a/bpkg/pkg-test.cli b/bpkg/pkg-test.cli index d9fb787..e2c2965 100644 --- a/bpkg/pkg-test.cli +++ b/bpkg/pkg-test.cli @@ -15,15 +15,17 @@ namespace bpkg "\h|SYNOPSIS| \c{\b{bpkg pkg-test}|\b{test} [] [] ...\n - \b{bpkg pkg-test}|\b{test} [] [] \b{--all}|\b{-a}} + \b{bpkg pkg-test}|\b{test} [] [] \b{--all}|\b{-a}\n + \b{bpkg pkg-test}|\b{test} [] [] (\b{--all-pattern} )...} \h|DESCRIPTION| - The \cb{pkg-test} command tests the specified packages (the first form) - or all the held packages (the second form, see \l{bpkg-pkg-status(1)}). - Additionally, immediate or all dependencies of these packages can also be - tested by specifying the \c{\b{--immediate}|\b{-i}} or - \c{\b{--recursive}|\b{-r}} options, respectively. Underneath, this + The \cb{pkg-test} command tests the specified packages (the first form), + all the held packages (the second form, see \l{bpkg-pkg-status(1)}), or + all the held packages that match any of the specified wildcard patterns + (the third form). Additionally, immediate or all dependencies of these + packages can also be tested by specifying the \c{\b{--immediate}|\b{-i}} + or \c{\b{--recursive}|\b{-r}} options, respectively. Underneath, this command doesn't do much more than run \cb{b test}. In the first form the specified packages must have been previously configured with \l{bpkg-pkg-build(1)} or \l{bpkg-pkg-configure(1)}. @@ -44,6 +46,14 @@ namespace bpkg "Test all held packages." } + strings --all-pattern + { + "", + "Test held packages that match the specified wildcard pattern. Repeat + this option to match multiple patterns. Note that you may need to quote + the pattern to prevent expansion by your shell." + } + bool --immediate|-i { "Also test immediate dependencies." diff --git a/bpkg/pkg-test.hxx b/bpkg/pkg-test.hxx index c9ec339..0cadabe 100644 --- a/bpkg/pkg-test.hxx +++ b/bpkg/pkg-test.hxx @@ -21,6 +21,7 @@ namespace bpkg o.recursive (), o.immediate (), o.all (), + o.all_pattern (), o.package_cwd (), args); } diff --git a/bpkg/pkg-uninstall.cli b/bpkg/pkg-uninstall.cli index 0e9d758..dead6d0 100644 --- a/bpkg/pkg-uninstall.cli +++ b/bpkg/pkg-uninstall.cli @@ -15,18 +15,20 @@ namespace bpkg "\h|SYNOPSIS| \c{\b{bpkg pkg-uninstall}|\b{uninstall} [] [] ...\n - \b{bpkg pkg-uninstall}|\b{uninstall} [] [] \b{--all}|\b{-a}} + \b{bpkg pkg-uninstall}|\b{uninstall} [] [] \b{--all}|\b{-a}\n + \b{bpkg pkg-uninstall}|\b{uninstall} [] [] (\b{--all-pattern} )...} \h|DESCRIPTION| The \cb{pkg-uninstall} command uninstalls the specified packages (the - first form) or all held packages (the second form, see - \l{bpkg-pkg-status(1)}). Additionally, immediate or all dependencies of - these specified packages can be also uninstalled by specifying the - \c{\b{--immediate}|\b{-i}} or \c{\b{--recursive}|\b{-r}} options, - respectively. Underneath, this command doesn't do much more than run - \cb{b uninstall}. In the first form the specified packages must have been - previously configured with \l{bpkg-pkg-build(1)} or + first form), all the held packages (the second form, see + \l{bpkg-pkg-status(1)}), or all the held packages that match any of the + specified wildcard patterns (the third form). Additionally, immediate or + all dependencies of these specified packages can be also uninstalled by + specifying the \c{\b{--immediate}|\b{-i}} or \c{\b{--recursive}|\b{-r}} + options, respectively. Underneath, this command doesn't do much more than + run \cb{b uninstall}. In the first form the specified packages must have + been previously configured with \l{bpkg-pkg-build(1)} or \l{bpkg-pkg-configure(1)}. Additional command line variables (, normally \cb{config.*}) can be @@ -45,6 +47,14 @@ namespace bpkg "Uninstall all held packages." } + strings --all-pattern + { + "", + "Uninstall held packages that match the specified wildcard pattern. + Repeat this option to match multiple patterns. Note that you may need + to quote the pattern to prevent expansion by your shell." + } + bool --immediate|-i { "Also uninstall immediate dependencies." diff --git a/bpkg/pkg-uninstall.hxx b/bpkg/pkg-uninstall.hxx index d3b6c63..94a8390 100644 --- a/bpkg/pkg-uninstall.hxx +++ b/bpkg/pkg-uninstall.hxx @@ -21,6 +21,7 @@ namespace bpkg o.recursive (), o.immediate (), o.all (), + o.all_pattern (), false /* package_cwd */, args); } diff --git a/bpkg/pkg-update.cli b/bpkg/pkg-update.cli index 531da4a..7887185 100644 --- a/bpkg/pkg-update.cli +++ b/bpkg/pkg-update.cli @@ -15,17 +15,19 @@ namespace bpkg "\h|SYNOPSIS| \c{\b{bpkg pkg-update}|\b{update} [] [] ...\n - \b{bpkg pkg-update}|\b{update} [] [] \b{--all}|\b{-a}} + \b{bpkg pkg-update}|\b{update} [] [] \b{--all}|\b{-a}\n + \b{bpkg pkg-update}|\b{update} [] [] (\b{--all-pattern} )...} \h|DESCRIPTION| The \cb{pkg-update} command updates the specified packages (the first - form) or all the held packages (the second form, see - \l{bpkg-pkg-status(1)}). Underneath, this command doesn't do much more - than run \cb{b update} (or one of its \c{update-for-*} variants; see - \cb{--for|-f}). In the first form the specified packages must have been - previously configured with \l{bpkg-pkg-build(1)} or - \l{bpkg-pkg-configure(1)}. + form), all the held packages (the second form, see + \l{bpkg-pkg-status(1)}), or all the held packages that match any of the + specified wildcard patterns (the third form). Underneath, this command + doesn't do much more than run \cb{b update} (or one of its + \c{update-for-*} variants; see \cb{--for|-f}). In the first form the + specified packages must have been previously configured with + \l{bpkg-pkg-build(1)} or \l{bpkg-pkg-configure(1)}. Additional command line variables (, normally \cb{config.*}) can be passed to the build system. Such variables apply to all the specified @@ -43,6 +45,14 @@ namespace bpkg "Update all held packages." } + strings --all-pattern + { + "", + "Update held packages that match the specified wildcard pattern. Repeat + this option to match multiple patterns. Note that you may need to quote + the pattern to prevent expansion by your shell." + } + string --for|-f { "", diff --git a/bpkg/pkg-update.hxx b/bpkg/pkg-update.hxx index 7eb4c37..72d8cd5 100644 --- a/bpkg/pkg-update.hxx +++ b/bpkg/pkg-update.hxx @@ -22,6 +22,7 @@ namespace bpkg false /* recursive */, false /* immediate */, o.all (), + o.all_pattern (), false /* package_cwd */, args); } diff --git a/tests/pkg-test.testscript b/tests/pkg-test.testscript index 5e212f4..c8b4a8e 100644 --- a/tests/pkg-test.testscript +++ b/tests/pkg-test.testscript @@ -42,6 +42,13 @@ test.options += --build-option -s info: run 'bpkg help pkg-test' for more information EOE + : all-all-pattern + : + $* --all --all-pattern 'lib*' 2>>EOE != 0 + error: both --all|-a and --all-pattern specified + info: run 'bpkg help pkg-test' for more information + EOE + : all-name : $* --all libbaz 2>>EOE != 0 @@ -49,6 +56,13 @@ test.options += --build-option -s info: run 'bpkg help pkg-test' for more information EOE + : all-pattern-name + : + $* --all-pattern 'lib*' libbaz 2>>EOE != 0 + error: both --all-pattern and package argument specified + info: run 'bpkg help pkg-test' for more information + EOE + : recursive-immediate : $* libbaz --recursive --immediate 2>>~%EOE% != 0 @@ -92,6 +106,29 @@ test.options += --build-option -s } } +: all-pattern +: +{ + : match + : + { + $clone_root_cfg; + + $* --all-pattern 'libf*' --all-pattern 'lib*' --all-pattern 'libz*' 2>>~%EOE% + %info: .+ has nothing to test% + tested libbaz/0.0.3 + EOE + } + + : not-match + : + { + $clone_root_cfg; + + $* --all-pattern 'libf*' 2>'info: nothing to test' + } +} + : immediate : { -- cgit v1.1