英文:
Is it possible to pass a CLI flag to Make?
问题
我有一个Makefile文件,其中我添加了以下两个目标,它们在Docker容器内运行Symfony命令:
amqp-poll: ## 启动amqp轮询
@$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll"
amqp-purge: ## 清空amqp队列
@$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll --purge"
是否可以传递一个标志,使我能够运行 `make amqp-poll --purge` 而不是 `make amqp-purge`?
换句话说,我想合并这两个目标,使用双破折号标志有选择地触发第二个目标中的逻辑。
(我查阅了 `ifdef`,但它似乎需要一个值,对吧?我更感兴趣的是一个简单的标志。)
这种做法可能吗?
英文:
I have a Makefile, to which I have added the following two targets that run Symfony commands inside a Docker container:
amqp-poll: ## Start amqp polling
@$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll"
amqp-purge: ## Purge amqp queues
@$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll --purge"
Is it possible to pass in a flag so that I am, for example, running make amqp-poll --purge
rather than make amqp-purge
?
In other words, I would like to merge these two targets, with the use of a double-dash flag selectively triggering the logic in the second target.
(I looked into ifdef
, but it looks like that requires a value, right? I'm more interested in a simple flag.)
Is this possible?
答案1
得分: 1
是的,这是可能的。Makefile:
可选的默认初始化以抑制警告
AMQP_FLAGS ?=
amqp-poll: ## 启动AMQP轮询
@$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll $(AMQP_FLAGS)"
命令行:
make amqp-poll AMPQ_FLAGS=--purge
<details>
<summary>英文:</summary>
Yes, it is possible. Makefile:
Optional default initialization to suppress warnings
AMQP_FLAGS ?=
amqp-poll: ## Start amqp polling
@$(DOCKER_COMPOSE) exec -it $(SERVICE_CONTAINER) /bin/bash -c "php /code/backend/app-new/console amqp:poll $(AMQP_FLAGS)"
Command-line:
make amqp-poll AMPQ_FLAGS=--purge
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论