Skip to content

Issue, label Directive - fails to work when directive output: prefixed in Taskfile #933

@dsbitor

Description

@dsbitor

Problem:

The directive label's function is to allow a task to output a
text string, other than the task name when the task is executed.

In the official documentation states that label:

'Overrides the name of the task in the output when a task is
run. Supports variables.'

If the label directive is set for a task, say to Hello
with label: 'Hello' and the directive output: prefixed is
also included in the Taskfile, the output is not as expected.

Further, the outcome is the same if the label text is set
dynamically using a Task variable.

See the section 'Analysis' below.

Test Taskfile.yml

The Taskfile below contains two tasks one where label is a static
string and one task where the label is from a dynamically loaded
task variable.

	version: '3'
	
	output: prefixed
	
	vars:
	  VERSION: '0.2'
	  BACKUP_TIME:
	    sh: date +"%Y-%m-%d_%H:%M:%S"
	  SYSTEM_ID:
	     sh: |
	         hostname
	  BACKUP_ID: '{{.SYSTEM_ID}}_{{.BACKUP_TIME}}'
	
	tasks:
	  default:
	    # Predefined string for label
	    label:   'Hello'
	    desc: Display Task variables
	    cmds:
	      - |
	        echo "HostName:"{{.SYSTEM_ID}}
	        echo "Backup_Time:"{{.BACKUP_TIME}}
	        echo "Backup ID:" {{.SYSTEM_ID }}{{.BACKUP_TIME}}
	        echo "Version:" {{.VERSION}}
	
	  dynamic:
	    # Dynamic string for label
	    label: '{{.BACKUP_ID}}'
	    desc: Display Task variables with label set dynamically
	    cmds:
	      - |
	        echo "HostName:"{{.SYSTEM_ID}}
	        echo "Backup_Time:"{{.BACKUP_TIME}}
	        echo "Backup ID:" {{.SYSTEM_ID }}{{.BACKUP_TIME}}
	        echo "Backup ID 2:" {{.VERSION}}

Output Generated and expected

Output generated from the task default:

	task: [Hello] echo "HostName:"MBP.local
	echo "Backup_Time:"2022-11-14_13:41:47
	echo "Backup ID:" MBP.local2022-11-14_13:41:47
	echo "Version:" 0.2
	
	[default] HostName:MBP.local
	[default] Backup_Time:2022-11-14_13:41:47
	[default] Backup ID: MBP.local2022-11-14_13:41:47
	[default] Version: 0.2

Output expected from the task default:

	task: [Hello] echo "HostName:"MBP.local
	echo "Backup_Time:"2022-11-14_13:41:47
	echo "Backup ID:" MBP.local2022-11-14_13:41:47
	echo "Version:" 0.2
	
	[Hello] HostName:MBP.local
	[Hello] Backup_Time:2022-11-14_13:41:47
	[Hello] Backup ID: MBP.local2022-11-14_13:41:47
	[Hello] Version: 0.2

Output generated from the task dynamic:

	task: [MBP.local_2022-11-14_13:42:39] echo "HostName:"MBP.local
	echo "Backup_Time:"2022-11-14_13:42:39
	echo "Backup ID:" MBP.local2022-11-14_13:42:39
	echo "Backup ID 2:" 0.2
	
	[dynamic] HostName:MBP.local
	[dynamic] Backup_Time:2022-11-14_13:42:39
	[dynamic] Backup ID: MBP.local2022-11-14_13:42:39
	[dynamic] Backup ID 2: 0.2

Output expected from the task dynamic:

	task: [MBP.local_2022-11-14_13:42:39] echo "HostName:"MBP.local
	echo "Backup_Time:"2022-11-14_13:42:39
	echo "Backup ID:" MBP.local2022-11-14_13:42:39
	echo "Backup ID 2:" 0.2
	
	[MBP.local_2022-11-14_13:42:39] HostName:MBP.local
	[MBP.local_2022-11-14_13:42:39] Backup_Time:2022-11-14_13:42:39
	[MBP.local_2022-11-14_13:42:39] Backup ID: MBP.local2022-11-14_13:42:39
	[MBP.local_2022-11-14_13:42:39] Backup ID 2: 0.2

Analysis

The label directive works for both static and dynamic
values and does label the first instance of the task name as
seen in line 1 of both sets of output.

The label directive does not output the substitute name
in the output strings from the echo commands, as requested by
output prefixed directive. The output reverts to the
task name.

  • Task Version 3.17
  • Operating System: OS X Version Monterey 12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formattingChanges related to output and formatting.

    Type

    No fields configured for bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions