Explore the workspace
There is a way to view the workspace structure, and that is to execute the ws command:
poly ws
This will view the whole workspace as plain data. This data structure is produced by the tool itself and is used by all the commands internally. The commands only operate on this hash map and are not performing any io operations, such as touching the disk or executing git commands. Instead, everything is prepared so that all commands can be executed in memory.
This will not only simplify the code of the tool itself but also gives us, as a user of the tool, a way to explore the complete state of the workspace (or other people's workspaces).
We can limit the "query" by passing in get, here against the doc-example, e.g.:
poly ws get:settings
{:active-profiles #{"default"},
:color-mode "none",
:compact-views #{},
:default-profile-name "default",
:empty-character ".",
:interface-ns "interface",
:m2-dir "/Users/joakimtengstrand/.m2",
:profile-to-settings {"default" {:paths ["components/user/src"
:lib-deps {},
:component-names ["user"],
:base-names [],
:project-names []},
"remote" {:paths ["components/user-remote/src"
:lib-deps {},
:component-names ["user-remote"],
:base-names [],
:project-names []}},
:projects {"development" {:alias "dev"},
"command-line" {:alias "cl"
:test {:setup-fn project.command-line.test-setup/test-setup,
:teardown-fn project.command-line.test-setup/test-teardown},
"user-service" {:alias "user-s"}},
:tag-patterns {:stable "stable-*", :release "v[0-9]*"},
:thousand-separator ",",
:top-namespace "se.example",
:user-config-filename "/Users/joakimtengstrand/.polylith/config.edn",
:user-home "/Users/joakimtengstrand",
:vcs {:auto-add true,
:branch "main",
:git-root "/me/source/...",
:name "git",
:polylith {:branch "master",
:repo "https://github.com/polyfy/polylith.git"}
:stable-since {:tag "stable-lisa",
:sha "5091f18cfb182545be87e079e872205c3fb049d2"}}}
If we are only interested in a specific element in this structure, we can dig deeper into it:
poly ws get:settings:profile-to-settings:default:paths
...which outputs:
["components/user/src" "components/user/resources" "components/user/test"]
A good way to start digging into this data structure is to list all its keys:
poly ws get:keys
To list the components, type:
poly ws get:components:keys
["user" "user-remote"]
An even better way of exploring the data structure is to do it from a shell which we have already covered in the shell section.
To show the user component:
poly ws get:components:user
{:interface {:name "user",
:definitions [{:name "hello", :type "function", :parameters [{:name "name"}]}]}
:interface-deps {:src [], :test []}
:lib-deps {}
:lib-imports {:test ["clojure.test"]}
:lines-of-code {:src 9, :test 7}
:name "user"
:namespaces {:src [{:name "interface",
:namespace "se.example.user.interface"
:file-path "/Users/joakimtengstrand/source/polylith/example/output/example/components/user/src/se/example/user/interface.clj"
:imports ["se.example.user.core"]}
{:name "core"
:namespace "se.example.user.core"
:file-path "/Users/joakimtengstrand/source/polylith/example/output/example/components/user/src/se/example/user/core.clj"
:imports []}]
:test [{:name "interface-test"
:namespace "se.example.user.interface-test"
:file-path "/Users/joakimtengstrand/source/polylith/example/output/example/components/user/test/se/example/user/interface_test.clj"
:imports ["clojure.test" "se.example.user.interface"]}]}
:type "component"}
Earlier, we executed the libs command to show library usage. The same information is also stored in the workspace structure, e.g.:
poly ws get:components:user-remote:lib-deps
{"compojure/compojure" {:size 15172, :type "maven", :version "1.6.2"},
"http-kit/http-kit" {:size 191467, :type "maven", :version "2.4.0"},
"ring/ring" {:size 4621, :type "maven", :version "1.8.1"},
"slacker/slacker" {:size 28408, :type "maven", :version "0.17.0"}}
There is a way to store the workspace structure to a file, and that is to give the out parameter, e.g.:
poly ws out:ws.edn
An alternative way to reach the same result is to turn off the coloring and pipe to ws.edn:
poly ws color-mode:none > ws.edn
This can be used to share the workspace structure with others without sending them the whole workspace including the code. To load this workspace, they have to give the ws-file parameter, e.g.:
poly info ws-file:ws.edn
This will give the exact same output as if we execute poly info on the machine that created ws.edn. All commands except test and create can be executed when ws-file or ws-dir is given.
Here is an example where we inspect the arguments used to produce the file:
poly ws get:old:user-input:args ws-file:ws.edn
...which returns:
["ws" "out:ws.edn"]
A complete guide over the workspace structure keys can be found in the Workspace structure section.
Export as PDF
Copy link