unison/unison-src/transcripts/link.md
Paul Chiusano e32b2b0057 Improve testing of link/unlink
Adds a check for links by type, and a check for unlink
2021-08-31 11:15:35 -05:00

2.2 KiB

Linking definitions to metadata

.> builtins.mergeio

The link and unlink commands can be used to manage metadata linked to definitions. For example, you can link documentation to a definition:

use .builtin

coolFunction x = x * 2

coolFunction.doc = [: This is a cool function. :]
.> add
.> link coolFunction.doc coolFunction

You can use arbitrary Unison values and link them as metadata to definitions:

toCopyrightHolder author = match author with
  Author guid name -> CopyrightHolder guid name

alice = Author (GUID Bytes.empty) "Alice Coder"

coolFunction.license = License [toCopyrightHolder alice] [Year 2020] licenses.mit

licenses.mit = LicenseType [:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
:]
.> add
.> link coolFunction.license coolFunction
.> link alice coolFunction

We can look at the links we have:

.> links coolFunction
.> links coolFunction License

We can link the same metadata simultaneously to multiple definitions:

myLibrary.f x = x + 1
myLibrary.g x = x + 2
myLibrary.h x = x + 3
.> add
.> cd myLibrary
.myLibrary> find
.myLibrary> link .alice 1-3
.myLibrary> links f
.myLibrary> links g
.myLibrary> links h
.myLibrary> history

.> unlink coolFunction.doc coolFunction