Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Environmental Utility #272

Open
wants to merge 55 commits into
base: master
Choose a base branch
from

Conversation

RockfordWei
Copy link
Contributor

Environmental Operations

Usage

First, ensure the PerfectLib is imported in your Swift file:

import PerfectLib

You are now able to use the Env class to operate the environmental variables

Set

  • Single Variable Setting:

This statement is equal to bash command "export foo=bar"

Env.set("foo", value: "bar")
  • Group Setting:

It is also possible to set a group of variables in a dictionary style:

Env.set(["foo":"bar", "koo":"kar"])
// the result is identically the same as "export foo=bar && export koo=kar"

Get

  • Single variable query:
guard let foo = Env.get("foo") else {
	// there is no such a variable
}
  • Single variable query with a default value:
guard let foo = Env.get("foo", defaultValue: "bar") else {
	// there is no such a variable even with a default value??
}
  • Query all system variables:
let all = Env.get()
// the result of all is a dictionary [String: String]

Delete

  • Delete an environmental variable:
Env.del("foo")

# Environmental Operations

## Usage

First, ensure the `PerfectLib` is imported in your Swift file:

``` swift
import PerfectLib
```
You are now able to use the `Env` class to operate the environmental variables

### Set

- Single Variable Setting:

This statement is equal to bash command "export foo=bar"

``` swift
Env.set("foo", value: "bar")
```

- Group Setting:

It is also possible to set a group of variables in a dictionary style:

``` swift
Env.set(["foo":"bar", "koo":"kar"])
// the result is identically the same as "export foo=bar && export koo=kar"
```

### Get

- Single variable query:

``` swift
guard let foo = Env.get("foo") else {
	// there is no such a variable
}
```

- Single variable query with a default value:

``` swift
guard let foo = Env.get("foo", defaultValue: "bar") else {
	// there is no such a variable even with a default value??
}
```

- Query all system variables:

``` swift
let all = Env.get()
// the result of all is a dictionary [String: String]
```

### Delete

- Delete an environmental variable:

``` swift
Env.del("foo")
```
@ThomasDeLange
Copy link

This should be added👍🏼

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ RockfordWei
❌ RockyCognizant
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants