diff --git a/conan/cli/args.py b/conan/cli/args.py index 9533109f92b..b6651a0d055 100644 --- a/conan/cli/args.py +++ b/conan/cli/args.py @@ -38,8 +38,11 @@ def _add_common_install_arguments(parser, build_help, update_help=None): if build_help: parser.add_argument("-b", "--build", action="append", help=build_help) - parser.add_argument("-r", "--remote", action="append", default=None, - help='Look in the specified remote or remotes server') + group = parser.add_mutually_exclusive_group() + group.add_argument("-r", "--remote", action="append", default=None, + help='Look in the specified remote or remotes server') + group.add_argument("-nr", "--no-remote", action="store_true", + help='Do not use remote, resolve exclusively in the cache') if not update_help: update_help = ("Will check the remote and in case a newer version and/or revision of " diff --git a/conan/cli/commands/build.py b/conan/cli/commands/build.py index dbe84efb1c3..923cbdf6f2f 100644 --- a/conan/cli/commands/build.py +++ b/conan/cli/commands/build.py @@ -29,7 +29,7 @@ def build(conan_api, parser, *args): cwd = os.getcwd() path = conan_api.local.get_conanfile_path(args.path, cwd, py=True) folder = os.path.dirname(path) - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path, diff --git a/conan/cli/commands/create.py b/conan/cli/commands/create.py index 2ba5c58afbf..bb46285d1d0 100644 --- a/conan/cli/commands/create.py +++ b/conan/cli/commands/create.py @@ -44,7 +44,7 @@ def create(conan_api, parser, *args): conanfile_path=path, cwd=cwd, partial=args.lockfile_partial) - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args) out = ConanOutput() diff --git a/conan/cli/commands/export.py b/conan/cli/commands/export.py index 0e03b9d8edf..4fbb1634968 100644 --- a/conan/cli/commands/export.py +++ b/conan/cli/commands/export.py @@ -21,8 +21,11 @@ def export(conan_api, parser, *args): Export recipe to the Conan package cache """ common_args_export(parser) - parser.add_argument("-r", "--remote", action="append", default=None, - help='Look in the specified remote or remotes server') + group = parser.add_mutually_exclusive_group() + group.add_argument("-r", "--remote", action="append", default=None, + help='Look in the specified remote or remotes server') + group.add_argument("-nr", "--no-remote", action="store_true", + help='Do not use remote, resolve exclusively in the cache') parser.add_argument("-l", "--lockfile", action=OnceArgument, help="Path to a lockfile.") parser.add_argument("--lockfile-out", action=OnceArgument, @@ -35,7 +38,7 @@ def export(conan_api, parser, *args): cwd = os.getcwd() path = conan_api.local.get_conanfile_path(args.path, cwd, py=True) - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path, cwd=cwd, diff --git a/conan/cli/commands/graph.py b/conan/cli/commands/graph.py index 36312f7484c..5da4c62a36f 100644 --- a/conan/cli/commands/graph.py +++ b/conan/cli/commands/graph.py @@ -50,7 +50,7 @@ def graph_build_order(conan_api, parser, subparser, *args): path = conan_api.local.get_conanfile_path(args.path, cwd, py=None) if args.path else None # Basic collaborators, remotes, lockfile, profiles - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path, cwd=cwd, @@ -132,7 +132,7 @@ def graph_info(conan_api, parser, subparser, *args): path = conan_api.local.get_conanfile_path(args.path, cwd, py=None) if args.path else None # Basic collaborators, remotes, lockfile, profiles - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path, cwd=cwd, diff --git a/conan/cli/commands/install.py b/conan/cli/commands/install.py index 5e005106371..286d015601e 100644 --- a/conan/cli/commands/install.py +++ b/conan/cli/commands/install.py @@ -61,7 +61,7 @@ def install(conan_api, parser, *args): output_folder = None # Basic collaborators, remotes, lockfile, profiles - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path, cwd=cwd, diff --git a/conan/cli/commands/lock.py b/conan/cli/commands/lock.py index 14b98caf678..3a9c73501d1 100644 --- a/conan/cli/commands/lock.py +++ b/conan/cli/commands/lock.py @@ -32,7 +32,7 @@ def lock_create(conan_api, parser, subparser, *args): cwd = os.getcwd() path = conan_api.local.get_conanfile_path(args.path, cwd, py=None) if args.path else None - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile, conanfile_path=path, cwd=cwd, partial=True) profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args) diff --git a/conan/cli/commands/test.py b/conan/cli/commands/test.py index ca4018a5f22..8dea6e20075 100644 --- a/conan/cli/commands/test.py +++ b/conan/cli/commands/test.py @@ -28,7 +28,7 @@ def test(conan_api, parser, *args): conanfile_path=path, cwd=cwd, partial=args.lockfile_partial) - remotes = conan_api.remotes.list(args.remote) + remotes = conan_api.remotes.list(args.remote) if not args.no_remote else [] profile_host, profile_build = conan_api.profiles.get_profiles_from_args(args) out = ConanOutput() diff --git a/conans/test/integration/command/install/install_test.py b/conans/test/integration/command/install/install_test.py index 3f9ac7d6d21..303485cb2ca 100644 --- a/conans/test/integration/command/install/install_test.py +++ b/conans/test/integration/command/install/install_test.py @@ -298,6 +298,17 @@ def test_install_disabled_remote(client): assert "ERROR: Remote 'default' can't be found or is disabled" in client.out +def test_install_no_remotes(client): + client.save({"conanfile.py": GenConanfile("pkg", "0.1")}) + client.run("create .") + client.run("upload * --confirm -r default") + client.run("remove * -c") + client.run("install --requires=pkg/0.1 -nr", assert_error=True) + assert "ERROR: Package 'pkg/0.1' not resolved: No remote defined" in client.out + client.run("install --requires=pkg/0.1") # this works without issue + client.run("install --requires=pkg/0.1 -nr") # and now this too, pkg in cache + + def test_install_skip_disabled_remote(): client = TestClient(servers=OrderedDict({"default": TestServer(), "server2": TestServer(),