在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ash-shell/ash开源软件地址:https://github.com/ash-shell/ash开源编程语言:Shell 100.0%开源软件介绍:AshAsh is a modular Bash framework written with ease of use + reusability in mind.
Why should you care?Building command line tools in Bash is an extremely tedious and somewhat enigmatic task. There's quite a bit of boilerplate code you're going to have to write if you want your script to do more than just one thing, which will only clutter your script. In addition, your scripts will likely never be able to reference good code you've written from old scripts. Ash helps you get rid of all of your boilerplate by letting you call functions directly from the command line, while also providing a modular approach to scripting which will allow you to share code between scripts. You are able to build a module independently that functions as a CLI or as a library (or any combination of the two), and easily share your module with the world. InstallationInstalling Ash is really straightforward. Here I offer both a manual install approach, and also a simple one-liner you can paste in your terminal and get started immediately. The manual approach is recommended, as you will be more familiar with how Ash is set up. You should probably also never be running scripts from the output of a curl -- but I've still supplied a one-liner as I know a lot of people want a one-liner to get started.
Manually (recommended)First, clone down this repo into a place you'd like to keep Ash. We need to add the
After you've got the repo cloned down, symlink the cd /usr/local/bin # <-- This can be anything in your $PATH
ln -s /path/to/ash/repo/ash . You should now be good to go! via ScriptThe script runs this file. I recommended reading it! There's a possibility this script won't work you, as I do make an assumption that After you've read the install script, run this line right here, and you should be good to go: curl https://raw.githubusercontent.com/ash-shell/ash/master/install.sh | sh ModulesModules are the fundamental building blocks of Ash. They allow you to build out custom CLI's and libraries that can be used in any other Ash module.
Module StructureA module looks something like this:
ash_config.yamlThis is the only required file in an Ash module. This file tells Ash that your project is an Ash module. Here is an example name: Wrecker
package: github.com/ash-shell/wrecker
default_alias: wrecker
callable_prefix: Wrecker
test_prefix: Wrecker
callable.shThis file is only required if you want your library to be callable. The contents of this file are explained in this section. classes/This directory is where you would place your modules classes. Only class files at the root of this directory will be usable. This is an optional folder. The README of ash-shell/obj goes into full detail of how this all works.
lib/This is another optional directory. If you want your module to provide a functional based library, this is where you would place those files. Other packages will be able to import all of the root files in the Ash__import "your/modules/package/name" You can nest folders inside of Files in the test.shThis is the file in which you can write unit tests for your modules. The README of ash-shell/test goes into full detail of how this all works. Callable ModulesYou can build your module to be directly callable from the command line. The first thing you will need to do in your module is add callable_prefix: Wrecker Now you can create a
Your newly created callable file will look something like this: #!/bin/bash
Wrecker__callable_echo(){
echo "Hello Echo"
}
Wrecker__callable_main(){
echo "Hello"
normal_bash_function
}
normal_bash_function(){
echo "World"
} Callable FunctionsCallable functions are functions that can be called directly from the command line. If your module is installed and aliased as To call the ash wrecker:echo To call ash wrecker:main
ash wrecker Library ModulesLibrary modules are modules who provide either a Ash__import
Example usage: Ash__import "github.com/ash-shell/slugify" Obj__import
Obj__import "github.com/ash-shell/wrecker" "wrecker" The .ashrc FileThe This file is optional in terms of the Ash core, but may be required for some modules that require an It's worth noting that this is the first thing that is loaded in Ash, so module writers don't have to worry about a users License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论