Mercurial > octave-nkf
changeset 20510:7fa1970a655d
pkg.m: drop check of nargout value, the interpreter already does that.
* scripts/pkg/pkg.m: the interpreter already checks if there was any variable
that got no value assigned, there's no need to make the code more
complicated to cover that. Also, there's no point in calling describe()
with different nargout since it doesn't check nargout.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Thu, 03 Sep 2015 16:21:08 +0100 |
parents | 7d8ec197b08b |
children | c36f06ef7539 |
files | scripts/pkg/pkg.m |
diffstat | 1 files changed, 41 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/pkg/pkg.m Tue Sep 01 19:05:57 2015 +0200 +++ b/scripts/pkg/pkg.m Thu Sep 03 16:21:08 2015 +0100 @@ -362,22 +362,18 @@ switch (action) case "list" if (octave_forge) - if (nargout > 0) + if (nargout) local_packages = list_forge_packages (); else list_forge_packages (); endif else - if (nargout == 0) - installed_packages (local_list, global_list, files); - elseif (nargout == 1) - local_packages = installed_packages (local_list, global_list, files); - elseif (nargout == 2) + if (nargout) [local_packages, global_packages] = installed_packages (local_list, global_list, files); else - error ("too many output arguments requested"); + installed_packages (local_list, global_list, files); endif endif @@ -428,13 +424,13 @@ unload_packages (files, deps, local_list, global_list); case "prefix" - if (isempty (files) && nargout == 0) + if (isempty (files) && ! nargout) printf ("Installation prefix: %s\n", prefix); printf ("Architecture dependent prefix: %s\n", archprefix); - elseif (isempty (files) && nargout >= 1) + elseif (isempty (files) && nargout) local_packages = prefix; global_packages = archprefix; - elseif (numel (files) >= 1 && nargout <= 2 && ischar (files{1})) + elseif (numel (files) >= 1 && ischar (files{1})) prefix = tilde_expand (files{1}); if (! exist (prefix, "dir")) [status, msg] = mkdir (prefix); @@ -461,11 +457,11 @@ endif case "local_list" - if (isempty (files) && nargout == 0) + if (isempty (files) && ! nargout) disp (local_list); - elseif (isempty (files) && nargout == 1) + elseif (isempty (files) && nargout) local_packages = local_list; - elseif (numel (files) == 1 && nargout == 0 && ischar (files{1})) + elseif (numel (files) == 1 && ! nargout && ischar (files{1})) local_list = files{1}; if (! exist (local_list, "file")) try @@ -481,11 +477,11 @@ endif case "global_list" - if (isempty (files) && nargout == 0) + if (isempty (files) && ! nargout) disp (global_list); - elseif (isempty (files) && nargout == 1) + elseif (isempty (files) && nargout) local_packages = global_list; - elseif (numel (files) == 1 && nargout == 0 && ischar (files{1})) + elseif (numel (files) == 1 && ! nargout && ischar (files{1})) global_list = files{1}; if (! exist (global_list, "file")) try @@ -506,7 +502,7 @@ auto, verbose); global_packages = save_order (global_packages); save (global_list, "global_packages"); - if (nargout > 0) + if (nargout) local_packages = global_packages; endif else @@ -514,7 +510,7 @@ auto, verbose); local_packages = save_order (local_packages); save (local_list, "local_packages"); - if (nargout == 0) + if (! nargout) clear ("local_packages"); endif endif @@ -530,48 +526,36 @@ error ("you must specify at least one package or 'all' when calling 'pkg describe'"); endif ## FIXME: name of the output variables is inconsistent with their content - switch (nargout) - case 0 - describe (files, verbose, local_list, global_list); - case 1 - pkg_desc_list = describe (files, verbose, local_list, global_list); - local_packages = pkg_desc_list; - case 2 - [pkg_desc_list, flag] = describe (files, verbose, local_list, ... - global_list); - local_packages = pkg_desc_list; - global_packages = flag; - otherwise - error ("you can request at most two outputs when calling 'pkg describe'"); - endswitch + if (nargout) + [local_packages, global_packages] = describe (files, verbose, + local_list, global_list); + else + describe (files, verbose, local_list, global_list); + endif case "update" - if (nargout == 0) - installed_pkgs_lst = installed_packages (local_list, global_list); - if (numel (files) > 0) - update_lst = {}; - installed_names = {installed_pkgs_list.name}'; - for i = 1:numel (files) - idx = find (strcmp (files{i}, installed_names), 1); - if (isempty (idx)) - warning ("Package %s is not installed - not updating this package", files{i}); - else - update_lst = { update_lst, installed_pkgs_lst{idx} }; - endif - endfor - installed_pkgs_lst = update_lst; + installed_pkgs_lst = installed_packages (local_list, global_list); + if (numel (files) > 0) + update_lst = {}; + installed_names = {installed_pkgs_list.name}'; + for i = 1:numel (files) + idx = find (strcmp (files{i}, installed_names), 1); + if (isempty (idx)) + warning ("Package %s is not installed - not updating this package", files{i}); + else + update_lst = { update_lst, installed_pkgs_lst{idx} }; + endif + endfor + installed_pkgs_lst = update_lst; + endif + for i = 1:numel (installed_pkgs_lst) + installed_pkg_name = installed_pkgs_lst{i}.name; + installed_pkg_version = installed_pkgs_lst{i}.version; + forge_pkg_version = get_forge_pkg (installed_pkg_name); + if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) + feval (@pkg, "install", "-forge", installed_pkg_name); endif - for i = 1:numel (installed_pkgs_lst) - installed_pkg_name = installed_pkgs_lst{i}.name; - installed_pkg_version = installed_pkgs_lst{i}.version; - forge_pkg_version = get_forge_pkg (installed_pkg_name); - if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) - feval (@pkg, "install", "-forge", installed_pkg_name); - endif - endfor - else - error ("no output arguments available"); - endif + endfor otherwise error ("you must specify a valid action for 'pkg'. See 'help pkg' for details");