mask

授权协议 MIT License
开发语言 JavaScript
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 傅正豪
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

build status

mask is a CLI task runner which is defined by a simple markdown file. It searches for a maskfile.md in the current directory which it then parses for commands and arguments.

A maskfile.md is both a human-readable document and a command definition! Being documentation focused allows others to easily get started with your project's development setup by simply reading your maskfile.md. A nice advantage of using markdown is that syntax highlighting for code blocks is built-in to many editors and renderers like GitHub itself.

Here's the maskfile.md that mask itself uses as an example!

To get started, follow the guide below or check out the more advanced features mask has like positional args, optional flags, subcommands, other scripting runtimes and more!

Installation

Precompiled binaries for linux and macOS

Head to the Releases page and look for the latest published version. Under Assets you'll see zips available for download for linux and macOS. Once downloaded, you can unzip them and then move the mask binary to somewhere accessible in your $PATH like mv mask /usr/local/bin.

Homebrew

mask is available in Homebrew which allows you to install it via brew install mask.

Cargo

mask is published to crates.io which allows you to install it via cargo install mask.

From source

If you prefer to build from source, clone this repo and then run cargo build --release

Getting started

First, define a simple maskfile.md in your project.

# Tasks For My Project


<!-- A heading defines the command's name -->
## build

<!-- A blockquote defines the command's description -->
> Builds my project

<!-- A code block defines the script to be executed -->
~~~sh
echo "building project..."
~~~


## test

> Tests my project

You can also write documentation anywhere you want. Only certain types of markdown patterns
are parsed to determine the command structure.

This code block below is defined as js which means it will be ran with node. Mask also
supports other scripting runtimes including python, ruby and php!

~~~js
console.log("running tests...")
~~~

Then, try running one of your commands!

mask build
mask test

Features

Positional arguments

These are defined beside the command name within (round_brackets). They are required arguments that must be supplied for the command to run. Optional args are coming soon. The argument name is injected into the script's scope as an environment variable.

Example:

## test (file) (test_case)

> Run tests

~~~bash
echo "Testing $test_case in $file"
~~~

Named flags

You can define a list of named flags for your commands. The flag name is injected into the script's scope as an environment variable.

Example:

## serve

> Serve this directory

<!-- You must define OPTIONS right before your list of flags -->
**OPTIONS**
* port
    * flags: -p --port
    * type: string
    * desc: Which port to serve on

~~~sh
PORT=${port:-8080} # Set a fallback port if not supplied

if [[ "$verbose" == "true" ]]; then
    echo "Starting an http server on PORT: $PORT"
fi
python -m SimpleHTTPServer $PORT
~~~

You can also make your flag expect a numerical value by setting its type to number. This means mask will automatically validate it as a number for you. If it fails to validate, mask will exit with a helpful error message.

Example:

## purchase (price)

> Calculate the total price of something.

**OPTIONS**
* tax
    * flags: -t --tax
    * type: number
    * desc: What's the tax?

~~~sh
TAX=${tax:-1} # Fallback to 1 if not supplied
echo "Total: $(($price * $TAX))"
~~~

If you exclude the type field, mask will treat it as a boolean flag. If the flag is passed, its environment variable will be "true", otherwise it will be unset/non-existent.

Important to note that mask auto injects a very common boolean flag called verbose into every single command even if it's not used, which saves a bit of typing for you. This means every command implicitly has a -v and --verbose flag already.

Example:

## test

> Run the test suite

**OPTIONS**
* watch
    * flags: -w --watch
    * desc: Run tests on file change

~~~bash
[[ "$watch" == "true" ]] && echo "Starting in watch mode..."
[[ "$verbose" == "true" ]] && echo "Running with extra logs..."
~~~

Flags are optional by default. If you add required to your flag definition, mask will error if it isn't supplied by the user.

Example:

## ping

**OPTIONS**
* domain
    * flags: -d --domain
    * type: string
    * desc: Which domain to ping
    * required

~~~sh
ping $domain
~~~

Subcommands

Nested command structures can easily be created since they are simply defined by the level of markdown heading. H2 (##) is where you define your top-level commands. Every level after that is a subcommand.

Example:

## services

> Commands related to starting and stopping services

### services start (service_name)

> Start a service.

~~~bash
echo "Starting service $service_name"
~~~

### services stop (service_name)

> Stop a service.

~~~bash
echo "Stopping service $service_name"
~~~

You may notice above that the start and stop commands are prefixed with their parent command services. Prefixing subcommands with their ancestor commands may help readability in some cases, however, it is completely optional. The example below is the same as above, but without prefixing.

Example:

## services

> Commands related to starting and stopping services

### start (service_name)

> Start a service.

~~~bash
echo "Starting service $service_name"
~~~

### stop (service_name)

> Stop a service.

~~~bash
echo "Stopping service $service_name"
~~~

Support for other scripting runtimes

On top of shell/bash scripts, mask also supports using node, python, ruby and php as scripting runtimes. This gives you the freedom to choose the right tool for the specific task at hand. For example, let's say you have a serve command and a snapshot command. You could choose python to serve a simple directory and maybe node to run a puppeteer script that generates a png snapshot of each page.

Example:

## shell (name)

> An example shell script

Valid lang codes: sh, bash, zsh, fish... any shell that supports -c

~~~zsh
echo "Hello, $name!"
~~~


## node (name)

> An example node script

Valid lang codes: js, javascript

~~~js
const { name } = process.env;
console.log(`Hello, ${name}!`);
~~~


## python (name)

> An example python script

Valid lang codes: py, python

~~~python
import os
name = os.getenv("name", "WORLD")
print("Hello, " + name + "!")
~~~


## ruby (name)

> An example ruby script

Valid lang codes: rb, ruby

~~~ruby
name = ENV["name"] || "WORLD"
puts "Hello, #{name}!"
~~~


## php (name)

> An example php script

~~~php
$name = getenv("name") ?: "WORLD";
echo "Hello, " . $name . "!\n";
~~~

Windows support

You can even add powershell or batch code blocks alongside linux/macOS ones. Depending on which platform this runs on, the correct code block will be executed.

Example:

## link

> Build and link the binary globally

~~~bash
cargo install --force --path .
~~~

~~~powershell
[Diagnostics.Process]::Start("cargo", "install --force --path .").WaitForExit()
~~~

Automatic help and usage output

You don't have to spend time writing out help info manually. mask uses your command descriptions and options to automatically generate help output. For every command, it adds -h, --help flags and an alternative help <name> command.

Example:

mask services start -h
mask services start --help
mask services help start
mask help services start

All output the same help info:

mask-services-start
Start or restart a service.

USAGE:
    mask services start [FLAGS] <service_name>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Sets the level of verbosity
    -r, --restart    Restart this service if it's already running
    -w, --watch      Restart a service on file change

ARGS:
    <service_name>

Running mask from within a script

You can easily call mask within scripts if you need to chain commands together. However, if you plan on running mask with a different maskfile, you should consider using the $MASK utility instead which allows your scripts to be location-agnostic.

Example:

## bootstrap

> Installs deps, builds, links, migrates the db and then starts the app

~~~sh
mask install
mask build
mask link
# $MASK also works. It's an alias variable for `mask --maskfile <path_to_maskfile>`
# which guarantees your scripts will still work even if they are called from
# another directory.
$MASK db migrate
$MASK start
~~~

Inherits the script's exit code

If your command exits with an error, mask will exit with its status code. This allows you to chain commands which will exit on the first error.

Example:

## ci

> Runs tests and checks for lint and formatting errors

~~~sh
mask test \
    && mask lint \
    && mask format --check
~~~

Running mask with a different maskfile

If you're in a directory that doesn't have a maskfile.md but you want to reference one somewhere else, you can with the --maskfile <path_to_maskfile> option.

Example:

mask --maskfile ~/maskfile.md <subcommand>

Tip: Make a bash alias for this so you can call it anywhere easily

# Call it something fun
alias wask="mask --maskfile ~/maskfile.md"

# You can run this from anywhere
wask <subcommand>

Environment variable utilities

Inside of each script's execution environment, mask injects a few environment variable helpers that might come in handy.

$MASK

This is useful when running mask within a script. This variable allows us to call $MASK command instead of mask --maskfile <path> command inside scripts so that they can be location-agnostic (not care where they are called from). This is especially handy for global maskfiles which you may call from anywhere.

$MASKFILE_DIR

This variable is an absolute path to the maskfile's parent directory. Having the parent directory available allows us to load files relative to the maskfile itself which can be useful when you have commands that depend on other external files.

Documentation sections

If a heading doesn't have a code block, it will be treated as documentation and completely ignored.

Example:

## This is a heading with no script

It's useful as a place to document things like a setup guide or required dependencies
or tools that your commands may rely on.

Use cases

Here's some example scenarios where mask might be handy.

Project specific tasks

You have a project with a bunch of random build and development scripts or an unwieldy Makefile. You want to simplify by having a single, readable file for your team members to add and modify existing tasks.

Global system utility

You want a global utility CLI for a variety of system tasks such as backing up directories or renaming a bunch of files. This is easily possible by making a bash alias for mask --maskfile ~/my-global-maskfile.md.

FAQ

Is mask available as a lib?

The mask-parser crate is available. However, it's not yet documented nor considered stable.

Where did the inspiration come from?

I'm definitely not the first to come up with this idea of using markdown as a CLI structure definition.

My frustrations with make's syntax is what led me to search for other options. I landed on just for awhile which was a pretty nice improvement. My favourite feature of just is its support for other language runtimes, which is why mask also has this ability! However, it still didn't have some features I wanted like nested subcommands and multiple optional flags.

At some point in my searching, I came across maid which is where most of the inspiration for mask comes from. I thought it was brilliant that markdown could be used as a command definition format while still being so readable.

So why did I choose to rebuild the wheel instead of using maid? For one, I preferred installing a single binary, like just is, rather than installing an npm package with hundreds of deps. I also had a few ideas on how I could improve upon maid which is why mask supports multiple levels of nested subcommands as well as optional flags and positional args. Also... I just really wanted to build another thing with Rust :)

I also need to mention clap and pulldown-cmark which are really the core parts of mask that made it so easy to create.

Contributing

Check out our Contribution Guidelines before creating an issue or submitting a PR ��

Also, please review and follow the rules within our Code of Conduct ��

Author

Jake Deichert with the help of contributors.

  • 刚开始涉及到图像处理的时候,在opencv等库中总会看到mask这么一个参数,非常的不理解,在查询一系列资料之后,写下它们,以供翻阅。 什么是掩膜(mask) 数字图像处理中的掩膜的概念是借鉴于PCB制版的过程,在半导体制造中,许多芯片工艺步骤采用光刻技术,用于这些步骤的图形“底片”称为掩膜(也称作“掩模”),其作用是:在硅片上选定的区域中对一个不透明的图形模板遮盖,继而下面的腐蚀或扩散将只影响选

 相关资料
  • 问题内容: 我正在做一个数独求解器,为此,我希望我的JTextFields只接受数字123456789中的一个作为有效输入。因此,我将MaskFormatter与JFormattedTextField一起使用。但是,当我通过执行.setText(“”)清除所有TextField时,MaskFormatter不再起作用。清除文本框后,我可以再次在其中写入任何内容。为什么以及如何解决? 我的代码基本上

  • 问题内容: 就我而言, clipstobounds 和 maskstobounds 都执行相同的工作。 我找不到它们之间的任何区别。 有人请解释两者的不同之处。 问题答案: masksToBounds 扩展到其边界之外的该层的任何子层都将被裁剪到这些边界。在这种情况下,可以将层视为其子层的窗口;窗口边缘以外的任何内容都将不可见。当masksToBounds为NO时,不会发生裁剪。 当此属性的值为t

  • 问题内容: 如何在最新的python绑定(cv2)中将掩码应用于彩色图像?在 以前的python绑定最简单的方法是使用例如。 但是这个函数在cv2绑定中不可用。有什么解决办法吗 不使用样板代码? 问题答案: 在这里,如果已经有了掩码,可以使用’cv2.bitwise\u and’函数 图像。 检查以下代码:

  • 主要内容:本节引言:,1.BlurMaskFilter(模糊效果),2.EmbossMaskFilter(浮雕效果),3.注意事项,示例代码下载:,本节小结:本节引言: 在Android基础入门教程——8.3.1 三个绘图工具类详解的Paint方法中有这样一个方法: setMaskFilter(MaskFilter maskfilter): 设置MaskFilter,可以用不同的MaskFilter实现滤镜的效果,如滤化,立体等! 而我们一般不会直接去用这个MaskFilter,而是使用它的两个

  • 前面,我们已经学习如何使用 setfacl 和 getfacl 为用户或群组添加针对某目录或文件的 ACL 权限。例如: [root@localhost /]# getfacl project #file: project <-文件名 #owner: root <-文件的属主 #group: tgroup <-文件的属组 user::rwx <-用户名栏是空的,说明是所有者的权限 group::r

  • 本文向大家介绍C++获取本机MAC,IP,MASK地址的方法,包括了C++获取本机MAC,IP,MASK地址的方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了C++获取本机MAC,IP,MASK地址的方法,分享给大家供大家参考。具体方法如下: 希望本文所述对大家的C++程序设计有所帮助。

  • 问题内容: 我认为当输入值为0时将输出0,因此以下各层可能会跳过计算或其他操作。 如何运作? 例: 实际输出为:(数字是随机的) 但是,我认为输出将是: 问题答案: 实际上,设置嵌入层不会导致返回零向量。而是,嵌入层的行为不会改变,它将返回索引为零的嵌入向量。您可以通过检查Embedding层权重(即在您提到的示例中为)来确认这一点。取而代之的是,它将影响诸如RNN层之类的后续层的行为。 如果检查

  • 我尝试翻译掩码内容元素中的一些标签(TYPO3 10)。我首先创建了掩码元素,掩码创建了一个目录“typo3conf/ext/mask_project”。我创建了文件typo3conf/extmask_project/Resources/Private/Language/locallang.xlf,并在其中放置了一个标签read_more。 在我的流体模板(“typo3conf/ext/mask_