poly
Search…
Explore the workspace
There is a way to view the workspace structure, and that is to execute the ws command:
1
poly ws
Copied!
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.:
1
poly ws get:settings
Copied!
1
{:active-profiles #{"default"},
2
:color-mode "none",
3
:compact-views #{},
4
:default-profile-name "default",
5
:empty-character ".",
6
:interface-ns "interface",
7
:m2-dir "/Users/joakimtengstrand/.m2",
8
:profile-to-settings {"default" {:paths ["components/user/src"
9
"components/user/resources"
10
"components/user/test"],
11
:lib-deps {},
12
:component-names ["user"],
13
:base-names [],
14
:project-names []},
15
"remote" {:paths ["components/user-remote/src"
16
"components/user-remote/resources"
17
"components/user-remote/test"],
18
:lib-deps {},
19
:component-names ["user-remote"],
20
:base-names [],
21
:project-names []}},
22
:projects {"development" {:alias "dev"},
23
"command-line" {:alias "cl"
24
:test {:setup-fn project.command-line.test-setup/test-setup,
25
:teardown-fn project.command-line.test-setup/test-teardown},
26
"user-service" {:alias "user-s"}},
27
:tag-patterns {:stable "stable-*", :release "v[0-9]*"},
28
:thousand-separator ",",
29
:top-namespace "se.example",
30
:user-config-filename "/Users/joakimtengstrand/.polylith/config.edn",
31
:user-home "/Users/joakimtengstrand",
32
:vcs {:auto-add true,
33
:branch "main",
34
:git-root "/me/source/...",
35
:name "git",
36
:polylith {:branch "master",
37
:repo "https://github.com/polyfy/polylith.git"}
38
:stable-since {:tag "stable-lisa",
39
:sha "5091f18cfb182545be87e079e872205c3fb049d2"}}}
Copied!
If we are only interested in a specific element in this structure, we can dig deeper into it:
1
poly ws get:settings:profile-to-settings:default:paths
Copied!
...which outputs:
1
["components/user/src" "components/user/resources" "components/user/test"]
Copied!
A good way to start digging into this data structure is to list all its keys:
1
poly ws get:keys
Copied!
1
[:bases
2
:changes
3
:components
4
:interfaces
5
:messages
6
:name
7
:paths
8
:projects
9
:settings
10
:user-input
11
:version
12
:ws-dir
13
:ws-reader]
Copied!
To list the components, type:
1
poly ws get:components:keys
Copied!
1
["user" "user-remote"]
Copied!
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:
1
poly ws get:components:user
Copied!
1
{:interface {:name "user",
2
:definitions [{:name "hello", :type "function", :parameters [{:name "name"}]}]}
3
:interface-deps {:src [], :test []}
4
:lib-deps {}
5
:lib-imports {:test ["clojure.test"]}
6
:lines-of-code {:src 9, :test 7}
7
:name "user"
8
:namespaces {:src [{:name "interface",
9
:namespace "se.example.user.interface"
10
:file-path "/Users/joakimtengstrand/source/polylith/example/output/example/components/user/src/se/example/user/interface.clj"
11
:imports ["se.example.user.core"]}
12
{:name "core"
13
:namespace "se.example.user.core"
14
:file-path "/Users/joakimtengstrand/source/polylith/example/output/example/components/user/src/se/example/user/core.clj"
15
:imports []}]
16
:test [{:name "interface-test"
17
:namespace "se.example.user.interface-test"
18
:file-path "/Users/joakimtengstrand/source/polylith/example/output/example/components/user/test/se/example/user/interface_test.clj"
19
:imports ["clojure.test" "se.example.user.interface"]}]}
20
:type "component"}
Copied!
Earlier, we executed the libs command to show library usage. The same information is also stored in the workspace structure, e.g.:
1
poly ws get:components:user-remote:lib-deps
Copied!
1
{"compojure/compojure" {:size 15172, :type "maven", :version "1.6.2"},
2
"http-kit/http-kit" {:size 191467, :type "maven", :version "2.4.0"},
3
"ring/ring" {:size 4621, :type "maven", :version "1.8.1"},
4
"slacker/slacker" {:size 28408, :type "maven", :version "0.17.0"}}
Copied!
There is a way to store the workspace structure to a file, and that is to give the out parameter, e.g.:
1
poly ws out:ws.edn
Copied!
An alternative way to reach the same result is to turn off the coloring and pipe to ws.edn:
1
poly ws color-mode:none > ws.edn
Copied!
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.:
1
poly info ws-file:ws.edn
Copied!
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:
1
poly ws get:old:user-input:args ws-file:ws.edn
Copied!
...which returns:
1
["ws" "out:ws.edn"]
Copied!
A complete guide over the workspace structure keys can be found in the Workspace structure section.
.
Last modified 2mo ago
Copy link