Repository: conan-io/conan

Issue:
Wrong message about "conan link"
remover.py, line 103, the message when you try to remove a package being an editable is: `WARN: Package 'zlib/1.2.11@conan/stable' is installed as editable, unlink it first using command 'conan link zlib/1.2.11@conan/stable --remove'`

Discussion:

Patch:
diff --git a/conans/client/command.py b/conans/client/command.py
index 08ce1705a..9a4a7f98f 100644
--- a/conans/client/command.py
+++ b/conans/client/command.py
@@ -208,10 +208,21 @@ class Command(object):
                             action=OnceArgument)
         parser.add_argument("-j", "--json", default=None, action=OnceArgument,
                             help='json output file')
+        parser.add_argument('--raw', default=None, action=OnceArgument,
+                            help='Print just the value of the requested attribute')
 
         args = parser.parse_args(*args)
-        result = self._conan.inspect(args.path_or_reference, args.attribute, args.remote)
-        Printer(self._user_io.out).print_inspect(result)
+
+        if args.raw and args.attribute:
+            raise ConanException("Argument '--raw' is incompatible with '-a'")
+
+        if args.raw and args.json:
+            raise ConanException("Argument '--raw' is incompatible with '--json'")
+
+        attributes = [args.raw, ] if args.raw else args.attribute
+
+        result = self._conan.inspect(args.path_or_reference, attributes, args.remote)
+        Printer(self._user_io.out).print_inspect(result, raw=args.raw)
         if args.json:
             json_output = json.dumps(result)
             if not os.path.isabs(args.json):
@@ -1432,9 +1443,14 @@ class Command(object):
                                          prog="conan workspace")
         subparsers = parser.add_subparsers(dest='subcommand', help='sub-command help')
 
-        install_parser = subparsers.add_parser('install', help='same as a "conan install" command '
-                                               'but using the workspace data from the file')
-        install_parser.add_argument('path', help='path to workspace definition file')
+        install_parser = subparsers.add_parser('install',
+                                               help='same as a "conan install" command'
+                                                    ' but using the workspace data from the file. If'
+                                                    ' no file is provided, it will look for a file'
+                                                    ' named "conanws.yml"')
+        install_parser.add_argument('path', help='path to workspace definition file (it will look'
+                                                 ' for a "conanws.yml" inside if a directory is'
+                                                 ' given)')
         _add_common_install_arguments(install_parser, build_help=_help_build_policies)
 
         args = parser.parse_args(*args)
diff --git a/conans/client/printer.py b/conans/client/printer.py
index e1ab99f00..9f2a17a7d 100644
--- a/conans/client/printer.py
+++ b/conans/client/printer.py
@@ -20,7 +20,7 @@ class Printer(object):
     def __init__(self, out):
         self._out = out
 
-    def print_inspect(self, inspect):
+    def print_inspect(self, inspect, raw=False):
         for k, v in inspect.items():
             if k == "default_options":
                 if isinstance(v, str):
@@ -29,12 +29,18 @@ class Printer(object):
                     v = OptionsValues(v)
                 elif isinstance(v, list):
                     v = OptionsValues(tuple(v))
-            if isinstance(v, (dict, OptionsValues)):
-                self._out.writeln("%s:" % k)
-                for ok, ov in sorted(v.items()):
-                    self._out.writeln("    %s: %s" % (ok, ov))
+                elif isinstance(v, dict):
+                    v = OptionsValues(v)
+
+            if raw:
+                self._out.write(str(v))
             else:
-                self._out.writeln("%s: %s" % (k, str(v)))
+                if isinstance(v, (dict, OptionsValues)):
+                    self._out.writeln("%s:" % k)
+                    for ok, ov in sorted(v.items()):
+                        self._out.writeln("    %s: %s" % (ok, ov))
+                else:
+                    self._out.writeln("%s: %s" % (k, str(v)))
 
     def print_info(self, data, _info, package_filter=None, show_paths=False, show_revisions=False):
         """ Print in console the dependency information for a conan file
diff --git a/conans/client/remover.py b/conans/client/remover.py
index b25fe740c..de6ca8675 100644
--- a/conans/client/remover.py
+++ b/conans/client/remover.py
@@ -101,8 +101,8 @@ class ConanRemover(object):
 
     @staticmethod
     def _message_removing_editable(ref):
-        return "Package '{r}' is installed as editable, unlink it first using " \
-               "command 'conan link {r} --remove'".format(r=ref)
+        return "Package '{r}' is installed as editable, remove it first using " \
+               "command 'conan editable remove {r}'".format(r=ref)
 
     def _local_remove(self, ref, src, build_ids, package_ids):
         if self._cache.installed_as_editable(ref):
diff --git a/conans/model/workspace.py b/conans/model/workspace.py
index e8d9762cf..3703d0012 100644
--- a/conans/model/workspace.py
+++ b/conans/model/workspace.py
@@ -39,6 +39,7 @@ class LocalPackage(object):
 
 
 class Workspace(object):
+    default_filename = "conanws.yml"
 
     def generate(self, cwd, graph, output):
         if self._ws_generator == "cmake":
@@ -90,6 +91,10 @@ class Workspace(object):
         self._cache = cache
         self._ws_generator = None
         self._workspace_packages = OrderedDict()  # {reference: LocalPackage}
+
+        if not os.path.isfile(path):
+            path = os.path.join(path, self.default_filename)
+
         self._base_folder = os.path.dirname(path)
         try:
             content = load(path)


Test patch:
diff --git a/conans/test/functional/command/inspect_test.py b/conans/test/functional/command/inspect_test.py
index e43f61f3e..3c3000695 100644
--- a/conans/test/functional/command/inspect_test.py
+++ b/conans/test/functional/command/inspect_test.py
@@ -338,3 +338,81 @@ default_options:
     bar: True
     foo: True
 """, client.out)
+
+
+class InspectRawTest(unittest.TestCase):
+    conanfile = textwrap.dedent("""
+        from conans import ConanFile
+        
+        class Pkg(ConanFile):
+            name = "MyPkg"
+            version = "1.2.3"
+            author = "John Doe"
+            url = "https://john.doe.com"
+            settings = "os", "arch", "build_type", "compiler"
+            options = {"foo": [True, False], "bar": [True, False]}
+            default_options = "foo=True", "bar=True"
+            
+            _private = "Nothing"
+
+            def build(self):
+                pass
+        """)
+
+    def test_no_field_or_multiple(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+        client.run("inspect . --raw", assert_error=True)
+        client.run("inspect . --raw=name --raw=version", assert_error=True)
+
+    def test_incompatible_commands(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+
+        client.run("inspect . --raw=name -a=version", assert_error=True)
+        self.assertIn("ERROR: Argument '--raw' is incompatible with '-a'", client.out)
+
+        client.run("inspect . --raw=name --json=tmp.json", assert_error=True)
+        self.assertIn("ERROR: Argument '--raw' is incompatible with '--json'", client.out)
+
+    def test_invalid_field(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+        client.run("inspect . --raw=not_exists", assert_error=True)
+        self.assertIn("ERROR: 'Pkg' object has no attribute 'not_exists'", client.out)
+
+    def test_private_field(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+        client.run("inspect . --raw=_private")
+        self.assertEqual("Nothing", client.out)
+
+    def test_settings(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+        client.run("inspect . --raw=settings")
+        self.assertEqual("('os', 'arch', 'build_type', 'compiler')", client.out)
+
+    def test_options_dict(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+        client.run("inspect . --raw=options")
+        self.assertEqual("{'foo': [True, False], 'bar': [True, False]}", client.out)
+
+    def test_default_options_list(self):
+        client = TestClient()
+        client.save({"conanfile.py": self.conanfile})
+        client.run("inspect . --raw=default_options")
+        self.assertEqual("bar=True\nfoo=True", client.out)
+
+    def test_default_options_dict(self):
+        client = TestClient()
+        conanfile = textwrap.dedent("""
+            from conans import ConanFile
+            
+            class Lib(ConanFile):
+                default_options = {"dict": True, "list": False}
+            """)
+        client.save({"conanfile.py": conanfile})
+        client.run("inspect . --raw=default_options")
+        self.assertEqual("dict=True\nlist=False", client.out)
diff --git a/conans/test/functional/editable/forbidden_commands_test.py b/conans/test/functional/editable/forbidden_commands_test.py
index e2d9e503a..1d96c1e1b 100644
--- a/conans/test/functional/editable/forbidden_commands_test.py
+++ b/conans/test/functional/editable/forbidden_commands_test.py
@@ -24,13 +24,13 @@ class ForbiddenRemoveTest(unittest.TestCase):
         t.run('editable add . {}'.format(ref))
         self.assertTrue(t.cache.installed_as_editable(ref))
         t.run('remove {} --force'.format(ref), assert_error=True)
-        self.assertIn("Package 'lib/version@user/name' is installed as editable, unlink it first "
-                      "using command 'conan link lib/version@user/name --remove'", t.out)
+        self.assertIn("Package 'lib/version@user/name' is installed as editable, remove it first "
+                      "using command 'conan editable remove lib/version@user/name'", t.out)
 
         # Also with a pattern, but only a warning
         t.run('remove lib* --force')
         self.assertIn("WARN: Package 'lib/version@user/name' is installed as editable, "
-                      "unlink it first using command 'conan link lib/version@user/name --remove'",
+                      "remove it first using command 'conan editable remove lib/version@user/name'",
                       t.out)
         self.assertTrue(t.cache.installed_as_editable(ref))
 
diff --git a/conans/test/functional/workspace/workspace_test.py b/conans/test/functional/workspace/workspace_test.py
index 0373e6ee6..03d748557 100644
--- a/conans/test/functional/workspace/workspace_test.py
+++ b/conans/test/functional/workspace/workspace_test.py
@@ -924,3 +924,55 @@ class Pkg(ConanFile):
         for p in ("HelloC", "HelloB", "HelloA"):
             self.assertIn("add_subdirectory(${PACKAGE_%s_SRC} ${PACKAGE_%s_BUILD})" % (p, p),
                           conanws_cmake)
+
+    def test_default_filename(self):
+        client = TestClient()
+        path_to_editable = os.path.join(client.current_folder, "A")
+
+        project = dedent("""
+            editables:
+                HelloA/0.1@lasote/stable:
+                    path: {path_to_editable}
+            layout: layout
+            workspace_generator: cmake
+            root: HelloA/0.1@lasote/stable
+            """.format(path_to_editable=path_to_editable))
+
+        conanfile = dedent("""
+            from conans import ConanFile
+
+            class Lib(ConanFile):
+                pass
+            """)
+
+        layout = dedent("""
+            [build_folder]
+            [source_folder]
+            """)
+
+        client.save({"conanfile.py": conanfile}, path=path_to_editable)
+        ws_folder = temp_folder()
+        client.save({os.path.join(ws_folder, Workspace.default_filename): project,
+                     os.path.join(ws_folder, "layout"): layout})
+
+        # For the right folder, it works
+        client.run('workspace install "{}"'.format(ws_folder))
+        conanws_cmake = load(os.path.join(client.current_folder, "conanworkspace.cmake"))
+        self.assertIn("macro(conan_workspace_subdirectories)", conanws_cmake)
+
+        # For a non existing folder, it will try to load the default filename (it fails)
+        non_existing = temp_folder()
+        client.run('workspace install "{}"'.format(non_existing), assert_error=True)
+        trial_path = os.path.join(non_existing, Workspace.default_filename)
+        self.assertIn("ERROR: Couldn't load workspace file in {}".format(trial_path), client.out)
+
+        # For an existing file, it will try to use it (will fail because of the format)
+        invalid_file = os.path.join(ws_folder, "layout")
+        client.run('workspace install "{}"'.format(invalid_file), assert_error=True)
+        self.assertIn("ERROR: There was an error parsing", client.out)
+
+        # For an existing folder, without the default file (it will fail looking for it)
+        no_default_file = os.path.join(client.current_folder)
+        client.run('workspace install "{}"'.format(no_default_file), assert_error=True)
+        trial_path = os.path.join(no_default_file, Workspace.default_filename)
+        self.assertIn("ERROR: Couldn't load workspace file in {}".format(trial_path), client.out)