bacon icon indicating copy to clipboard operation
bacon copied to clipboard

add alias to job configuration

Open tversteeg opened this issue 1 year ago • 8 comments

This allows you to write:

[jobs.example]
alias = ["ex", "exs"]
command = []

So you can do bacon example, bacon ex and bacon exs.

tversteeg avatar Jan 12 '25 03:01 tversteeg

Is that really needed ?

This raises a question for users: when defining a job so as to replace another one, which is frequent, do you also automatically replace the aliases? Or do you have to specify the same set of aliases ?

Canop avatar Jan 12 '25 07:01 Canop

If it's really needed is of course highly subjective, but for my use cases it would be a nice feature.

This raises a question for users: when defining a job so as to replace another one, which is frequent, do you also automatically replace the aliases? Or do you have to specify the same set of aliases ?

I would say that it should completely replace the existing aliases, that would also be the current implementation.

tversteeg avatar Jan 13 '25 02:01 tversteeg

I wasn't clear.

Imagine there's a team specific job "check" with alias "c", and a key-binding c = "job:check". Some team member get used to bacon c.

Now, on a project of this team, a bacon.toml defines a new "check"job because it uses special features maybe. Most members of the team will probably be surprised that bacon check and bacon c no longer do the same thing, and that the c shortcut doesn't call anymore the same job than called with bacon c job.

Canop avatar Jan 13 '25 05:01 Canop

The c shortcut not calling the new "check" job is not related to this PR, right?

If the new "check" job definition doesn't add the "c" alias, bacon check would work as intended and bacon c would throw an error that the job could not be found. I think this behavior makes sense.

Another option would be to merge all aliases from each previous job definition in the new job definition.

Yet another option would be to keep the previous job definitions and still allow their aliases to be called if they are not overwritten in the new definition.

tversteeg avatar Jan 13 '25 05:01 tversteeg

Other user opinions welcome

Canop avatar Jan 16 '25 06:01 Canop

IMHO I actually think adding aliases complicates the mental for me a bit of how bacon works and which job I would expect to actually be run. I don't personally have a need for aliases and it doesn't really affect me either way as I generally work with hotkeys and do not restart bacon to change job so I don't really have a horse in the race. That disclaimer added if I did need aliases I think I would create a job for each alias instead of defining them in the job I want aliased (Example below). I think that would make it more obvious what priority they have based on where they are defined. It is more typing so if it were something I used often I could see how I would want the syntactic sugar instead.

[jobs.example]
command = ["cargo", "run", "--example"]
need_stdout = true
allow_warnings = true

[jobs.ex]
command = ["echo", "alias used"]
on_success = "job:example"

[jobs.exs]
command = ["echo", "alias used"]
on_success = "job:example"

c-git avatar Jan 16 '25 21:01 c-git

Having given this a bit more thought, I think with the use of global jobs. The extra typing might be a one time effort and adding diminishes the value of adding aliases in my opinion. @tversteeg do you normally have different aliases per project or are they just things you could add to prefs.toml?

c-git avatar Feb 03 '25 15:02 c-git

If I did need aliases I think I would create a job for each alias instead of defining them in the job I want aliased (Example below). I think that would make it more obvious what priority they have based on where they are defined. It is more typing so if it were something I used often I could see how I would want the syntactic sugar instead.

[jobs.example]
command = ["cargo", "run", "--example"]
need_stdout = true
allow_warnings = true

[jobs.ex]
command = ["echo", "alias used"]
on_success = "job:example"

[jobs.exs]
command = ["echo", "alias used"]
on_success = "job:example"

That's actually a good workaround that would also fulfill my current needs.

Do you normally have different aliases per project or are they just things you could add to prefs.toml?

I have different aliases per project, not globally.

@Canop should I close this PR?

tversteeg avatar Feb 06 '25 04:02 tversteeg