前端框架选型是企业提升开发效率与用户体验的关键因素
924
2022-10-26
一个命令行实用程序运行特定项目的shell命令
Easy
A command-line utility to run project-specific shell commands containing a lot of flags with long values (e.g. file location containing a lot of subdirectories) using short aliases, stored in configuration file (supported formats: yaml, toml and json).
Idea is grabbed from docker-compose utility (live example), which is missing for programs like ansible, packer, terraform and basically any other command that consumes a lot of boilerplate.
Installation
$ go get github.com/kpashka/easy
Concepts
Shortcut - is base replacement for some command. E.g. ansible-playbook -vvvv can be replaced by ansible or ans.Flags - command-line flags, replaced by shorter aliases.Target - final command line argument, usually target directory or a file to be executed by program.Commands - used in monolith shortcut types, a whitelist of subcommands to be executed, e.g. terraform plan
Shortcut Types
snowflake - a shortcut with a lot of unique aliases, without any overlapping names.monolith - a shortcut with single alias - environment, should exist in all flags and target.
Configuration
Example YAML configuration for both shortcut types:
---shortcuts:# Snowflake command example - Ansible- type: snowflake process: ansible-playbook -vvvv alias: ansible flags: - name: Inventory Files flag: "--inventory-file" aliases: amazon.ini: ansible/inventory/amazon.ini local: ansible/inventory/localhost.init vagrant.ini: ansible/inventory/vagrant.ini - name: Private Key Files flag: "--private-key" aliases: id_rsa: "~/.ssh/id_rsa" aws.pem: "~/.ssh/aws.pem" - name: SSH Users flag: "--user" aliases: pavel: pavel ubuntu: ubuntu ec2-user: ec2-user targets: - name: Provision Database alias: database.yml target: ansible/playbooks/database.yml - name: Provision Nginx alias: nginx.yml target: ansible/playbooks/nginx.yml# Monolith command example - Terraform- type: monolith process: terraform commands: - plan - apply flags: - name: State Files flag: "-state" aliases: stage: terraform/envs/stage/terraform.tfstate prod: terraform/envs/production/terraform.tfstate - name: Variable Files flag: "-var-file" aliases: stage: terraform/envs/stage/stage.tfvars prod: terraform/envs/production/production.tfvars targets: - name: Project Staging Environment alias: stage target: terraform/base/stage - name: Project Production Environment alias: production target: terraform/base/production
See other format examples in examples directory.
Example
Implying that we're using configuration above, you can run:
$ $(easy ansible vagrant.ini ec2-user id_rsa nginx.yml)
Instead of (not the worst example):
$ ansible-playbook -vvvv --inventory-file=ansible/inventory/vagrant.ini --private-key=~/.ssh/id_rsa --user=ec2-user ansible/playbooks/nginx.yml
Order of aliases doesn't matter, the only requirement is - the command itself should be the first argument:
$ easy ansible nginx.yml id_rsa vagrant.ini ec2-user
monolith commands require exactly 3 arguments - shortcut, (sub)command to execute and environment:
$ easy terraform plan production
Which will be compiled into:
$ terraform plan -state=terraform/envs/production/terraform.tfstate -var-file=terraform/envs/production/production.tfvars terraform/base/production
Environment variables
Available environment variables:
Name | Description | Default Value |
---|---|---|
EASY_CONFIG_FORMAT | Configuration format | yaml |
EASY_CONFIG_FILE | Path to configuration file | .easy.yml |
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~