Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 1 | // Copyright 2019 The CUE Authors |
Marcel van Lohuizen | 0240d4e | 2020-05-12 15:30:55 +0200 | [diff] [blame] | 2 | // |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 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 |
Marcel van Lohuizen | 0240d4e | 2020-05-12 15:30:55 +0200 | [diff] [blame] | 6 | // |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
Marcel van Lohuizen | 0240d4e | 2020-05-12 15:30:55 +0200 | [diff] [blame] | 8 | // |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 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 os |
| 16 | |
| 17 | // A Value are all possible values allowed in flags. |
| 18 | // A null value unsets an environment variable. |
Marcel van Lohuizen | 0240d4e | 2020-05-12 15:30:55 +0200 | [diff] [blame] | 19 | Value: bool | number | *string | null |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 20 | |
| 21 | // Name indicates a valid flag name. |
Marcel van Lohuizen | 0240d4e | 2020-05-12 15:30:55 +0200 | [diff] [blame] | 22 | Name: !="" & !~"^[$]" |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 23 | |
| 24 | // Setenv defines a set of command line flags, the values of which will be set |
| 25 | // at run time. The doc comment of the flag is presented to the user in help. |
| 26 | // |
| 27 | // To define a shorthand, define the shorthand as a new flag referring to |
| 28 | // the flag of which it is a shorthand. |
| 29 | Setenv: { |
| 30 | $id: "tool/os.Setenv" |
| 31 | |
Marcel van Lohuizen | 56c994d | 2020-04-21 16:20:36 +0200 | [diff] [blame] | 32 | {[Name]: Value} |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | // Getenv gets and parses the specific command line variables. |
| 36 | Getenv: { |
| 37 | $id: "tool/os.Getenv" |
| 38 | |
Marcel van Lohuizen | 56c994d | 2020-04-21 16:20:36 +0200 | [diff] [blame] | 39 | {[Name]: Value} |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | // Environ populates a struct with all environment variables. |
| 43 | Environ: { |
| 44 | $id: "tool/os.Environ" |
| 45 | |
| 46 | // A map of all populated values. |
| 47 | // Individual entries may be specified ahead of time to enable |
| 48 | // validation and parsing. Values that are marked as required |
| 49 | // will fail the task if they are not found. |
Marcel van Lohuizen | 56c994d | 2020-04-21 16:20:36 +0200 | [diff] [blame] | 50 | {[Name]: Value} |
Marcel van Lohuizen | 42346df | 2019-12-19 14:09:54 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // Clearenv clears all environment variables. |
| 54 | Clearenv: { |
| 55 | $id: "tool/os.Clearenv" |
| 56 | } |