makefile - Is it possible to use positional, rather than named, parameters in a Makefile?
问题描述
I have created a working target in my Makefile
, called test-path-testname
:
## Runs tests that match a file pattern and test name to speed up test time
test-path-testname: ensure-env
docker-compose run -p 9229:9229 \
-e TYPEORM_URL=postgres://postgres@postgres/someapp_test \
-e DATABASE_URL_READONLY=postgres://postgres@postgres/someapp_test \
server npm run test-all -t $(path) -- \
--detectOpenHandles --watchAll --verbose=false -t "$(testname)"
.PHONY: test-path-testname
It functions perfectly, using the path
and testname
parameters:
make path=usersArea testname="should create a new user" test-path-testname
However that command quite long - is there way I can use positional, rather than named, parameters in a Makefile
?
For example, I'd like to be able to run the above with:
make usersArea "should create a new user" test-path-testname
解决方案
No it is not possible because all non-options that do not contain a =
are treated as targets.
Edit after your comment with the motivation explained:
You are solving an XY problem. Instead of more variables, pick apart the target name $@
with substitutions:
test-path-testname:
@echo path=$(word 2,$(subst -, ,$@)) testname=$(word 3,$(subst -, ,$@))
docker-compose ... -t $(word 3,$(subst -, ,$@)) ...
This assumes there are exactly two hyphens in the target name.
推荐阅读
- node.js - 将数据从 api 传递到变量 Node.js
- angular - 运行 ionic start 时找不到 npm
- c# - 在分层架构中,应用层如何知道 Web URL?
- database - 数据库中的事务处理
- javascript - 如何在节点js中进行自定义日志记录
- java - hibernate-types-52(有时)在 text[] Postgres 列的字符串周围插入双引号
- python - 在另一个 python 程序中运行 Kivy App
- javascript - 使用 lodash 将数组分组为树“子”结构
- google-chrome-extension - 在开发过程中使用 CI/CD 和 update.xml 自动更新 Chrome 扩展
- angularjs - 使用 webpack(或 webpack 模块联合)将 React MFE 与 Angular JS 项目(父项目)集成