cuelang.org/go@v0.13.0/tools/trim/doc.go (about)

     1  // Copyright 2025 The CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package trim removes some redundant values from CUE sources.
    16  //
    17  // The most common use of trim is to remove duplicate values from data
    18  // where a definition now provides the same value. For example:
    19  //
    20  //	servers: [
    21  //		{role: "web", cpus: 1},
    22  //		{role: "db", cpus: 1},
    23  //		{role: "proxy", cpus: 1},
    24  //	]
    25  //
    26  //	#server: {
    27  //		role: string
    28  //		cpus: 1
    29  //	}
    30  //
    31  //	servers: [...#server]
    32  //
    33  // Trim will simplify this to:
    34  //
    35  //	servers: [
    36  //		{role: "web"},
    37  //		{role: "db"},
    38  //		{role: "proxy"},
    39  //	]
    40  //
    41  //	#server: {
    42  //		role: string
    43  //		cpus: 1
    44  //	}
    45  //
    46  //	servers: [...#server]
    47  //
    48  // This works with defaults too. Given:
    49  //
    50  //	servers: [
    51  //		{role: "web", cpus: 1},
    52  //		{role: "db", cpus: 4},
    53  //		{role: "proxy", cpus: 1},
    54  //	]
    55  //
    56  //	#server: {
    57  //		role: string
    58  //		cpus: *1 | int
    59  //	}
    60  //
    61  //	servers: [...#server]
    62  //
    63  // Trim will simplify this to:
    64  //
    65  //	servers: [
    66  //		{role: "web"},
    67  //		{role: "db", cpus: 4},
    68  //		{role: "proxy"},
    69  //	]
    70  //
    71  //	#server: {
    72  //		role: string
    73  //		cpus: *1 | int
    74  //	}
    75  //
    76  //	servers: [...#server]
    77  package trim