可以将CLI标志传递给Make吗?

huangapple go评论67阅读模式
英文:

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>



huangapple
  • 本文由 发表于 2023年3月8日 18:26:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定