orbit怎么打开php,Orbit 一个用于运行命令和从模板生成文件的简单工具

14af31926160a65598f2dbf8da91d29f.png

Orbit

A cross-platform task runner for executing commands and generating files from templates

68747470733a2f2f7472617669732d63692e6f72672f67756c69656e2f6f726269742e7376673f6272616e63683d6d617374657268747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f666a367136793735766475676e3939692f6272616e63682f6d61737465723f7376673d7472756568747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f67756c69656e2f6f726269743f7374617475732e73766768747470733a2f2f676f7265706f7274636172642e636f6d2f62616467652f6769746875622e636f6d2f67756c69656e2f6f7262697468747470733a2f2f636f6465636f762e696f2f67682f67756c69656e2f6f726269742f6272616e63682f6d61737465722f67726170682f62616467652e737667

Orbit started with the need to find a cross-platform alternative of make and sed -i commands. As it does not aim to be as powerful as these two commands, Orbit offers an elegant solution for running tasks and generating files from templates, whatever the platform you're using.

Menu

Install

Download the latest release of Orbit from the releases page. You can get Orbit for a large range of OS and architecture.

The file you downloaded is a compressed archive. You'll need to extract the Orbit binary and move it into a folder where you can execute it easily.

Linux/MacOS:

tar -xzf orbit*.tar.gz orbit

sudo mv ./orbit /usr/local/bin && chmod +x /usr/local/bin/orbit

Windows:

Right click on the file and choose Extract All.

Move the binary to a folder like C:\Orbit. Then, add it in your Path system environment variables. Click System, Advanced system settings, Environment Variables... and open Path under System variables. Edit the Variable value by adding the folder with the Orbit binary.

Alright, you're almost done

🤘! Let's check your installation by running:

orbit version

Generating a file from a template

Orbit uses the Go package text/template under the hood as a template engine. It provides a interesting amount of logic for your templates.

The Go documentation and the Hugo documentation cover a lot of features that aren't mentioned here. Don't hesitate to take a look at these links to understand the Go template engine!

😃

Also, Orbit provides Sprig library and three custom functions:

os which returns the current OS name at runtime (you may find all available names in the official documentation).

verbose which returns true if logging is set to info level.

debug which returns true if logging is set to debug level.

Command description

Base

orbit generate [flags]

Flags

-f --file

Specify the path of the template. This flag is required.

-o --output

Specify the output file which will be generated from the template.

Good to know: if no output is specified, Orbit will print the result to Stdout.

-p --payload

The flag -p allows you to specify many data sources which will be applied to your template:

orbit generate [...] -p "key_1,file_1.yml"

orbit generate [...] -p "key_1,file_1.yml;key_2,file_2.toml;key_3,file_3.json;key_4,.env;key_5,some raw data"

As you can see, Orbit handles 5 types of data sources:

YAML files (*.yaml, *.yml)

TOML files (*.toml)

JSON files (*.json)

.env files

raw data

The data will be accessible in your template through {{ .Orbit.my_key.my_data }}.

If you don't want to specify the payload each time your running orbit generate, you may also create a file named orbit-payload.yml in the folder where your running your command:

payload:

- key: my_key

value: my_file.yml

- key: my_other_key

value: Some raw data

By doing so, running orbit generate [...] will be equivalent to running orbit generate [...] -p "my_key,my_file.yml;my_other_key,Some raw data".

Note: you are able to override a data source from the file orbit-payload.yml if you set the same key in the -p flag.

-t --templates

The flag -t allows you to specify additional templates which are used in your template:

orbit generate [...] -t "template_1.txt"

orbit generate [...] -t "template_1.txt,template_2.yml"

orbit generate [...] -t "template_1.txt,template_2.yml,../../template_3.toml"

So, in order to generate a file from this template:

{{ template "additional_template.txt" }}

You should run:

orbit generate [...] -t "path/to/additional_template.txt"

If you don't want to specify the templates each time your running orbit generate, you may also use the file orbit-payload.yml in the folder where your running your command:

payload:

[...]

templates:

- template_1.txt

- template_2.yml

By doing so, running orbit generate [...] will be equivalent to running orbit generate [...] -t "template_1.txt,template_2.yml".

-v --verbose

Sets logging to info level.

-d --debug

Sets logging to debug level.

Basic example

Let's create our simple template template.yml:

companies:

{{- range $company := .Orbit.Values.companies }}

- name: {{ $company.name }}

launchers:

{{- range $launcher := $company.launchers }}

- {{ $launcher }}

{{ end }}

{{- end }}

And the data provided a YAML file named data-source.yml:

companies:

- name: SpaceX

launchers:

- Falcon 9

- Falcon Heavy

- name: Blue Origin

launchers:

- New Shepard

- New Glenn

agencies:

- name: ESA

launchers:

- Ariane 5

- Vega

The command for generating a file from this template is quite simple:

orbit generate -f template.yml -p "Values,data-source.yml" -o companies.yml

This command will create the companies.yml file with this content:

companies:

- name: SpaceX

launchers:

- Falcon 9

- Falcon Heavy

- name: Blue Origin

launchers:

- New Shepard

- New Glenn

Defining and running tasks

Command description

Base

orbit run [tasks] [flags]

Flags

-f --file

Like the make command with its Makefile, Orbit requires a configuration file (YAML, by default orbit.yml) where you define your tasks:

tasks:

- use: my_first_task

short: My first task short description

run:

- command [args]

- command [args]

- ...

- use: my_second_task

private: true

run:

- command [args]

- command [args]

- ...

the use attribute is the name of your task.

the short attribute is optional and is displayed when running orbit run.

the private attribute is optional and hides the considered task when running orbit run.

the run attribute is the stack of commands to run.

a command is a binary which is available in your $PATH.

Once you've created your orbit.yml file, you're able to run your tasks with:

orbit run my_first_task

orbit run my_second_task

orbit run my_first_task my_second_task

Notice that you may run nested tasks

🤘!

Also a cool feature of Orbit is its ability to read its configuration through a template.

For example, if you need to execute a platform specific script, you may write:

tasks:

- use: script

run:

{{ if ne "windows" os }}

- my_script.sh

{{ else }}

- .\my_script.bat

{{ end }}

Orbit will automatically detect the shell you're using (with the SHELL environment variable on POSIX system and COMSPEC on Windows).

Running the task script from the previous example will in fact executes cmd.exe /c .\my_script.bat on Windows or /bin/sh -c my_script.sh (or /bin/zsh -c my_script.sh etc.) on others OS.

Of course, if you want to specify the binary which is calling your commands, there is a shell attribute available:

tasks:

- use: script

shell: /bin/bash -c

run:

- command [args]

- ...

Last but not least, a task is able to call others tasks within the same context thanks to the run function:

tasks:

- use: task

run:

- {{ run "subtask_1" "subtask_2" }}

- use: subtask_1

run:

- command [args]

- ...

- use: subtask_2

run:

- command [args]

- ...

-p --payload

The flag -p allows you to specify many data sources which will be applied to your configuration file.

It works the same as the -p flag from the generate command.

Of course, you may also create a file named orbit-payload.yml in the same folder where you're executing Orbit.

-t --templates

The flag -t allows you to specify additional templates which are used in your configuration file.

It works the same as the -t flag from the generate command.

Of course, you may also create a file named orbit-payload.yml in the same folder where you're executing Orbit.

-v --verbose

Sets logging to info level.

-d --debug

Sets logging to debug level.

Basic example

Let's create our simple configuration file orbit.yml:

tasks:

- use: prepare

run:

- orbit generate -f configuration.template.yml -o configuration.yml -p "Data,config.json"

- echo "configuration.yml has been succesfully created!"

You are now able to run the task prepare with:

orbit run prepare

This task will:

create a file named configuration.yml

print configuration.yml has been succesfully created! to Stdout

Voilà!

😃

Would you like to update this documentation ? Feel free to open an issue.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值