# Switch argument for command template

**URL:** <https://resource.dopus.com/t/switch-argument-for-command-template/51677>\
**Category:** Help & Support\
**Created:** [July 5, 2024, 8:03pm UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677 "2024-07-05T20:03:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AstoriaBoy](https://resource.dopus.com/letter_avatar_proxy/v4/letter/a/58f4c7/32.png) [@AstoriaBoy](https://resource.dopus.com/u/AstoriaBoy)\
**Post date:** [July 5, 2024, 8:03pm UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677/1 "2024-07-05T20:03:31Z")

</div>

I've been trying to add both a kayword argument and a switch argument to my add-in script, but I must be doing something wrong. When I invoke my custom command without the switch argument, I can process the keyword argument just fine; when I add the switch, however, the keyword always comes up "undefined".

My command template looks like this:

`cmd2.template = "ARTIST/K, REPLACE/S";`

Here is the function code that processes the ARTIST argument:

```auto
var tag_to_add;
if (ScriptCommandData.func.args.got_arg.ARTIST) {
	var tag_to_add = d.func.args.ARTIST;
	DOpus.Output("Tag to add: " + tag_to_add);
}
else {
	DOpus.output("ERROR: no artist argument found");
	return;
}

```

When I call the function like this, it processes the argument correctly:

`add_artist ARTIST=chet_baker`

However, when I call the function like this:

`add_artist ARTIST=chet_baker REPLACE`

I get "ERROR: no artist argument found". I've tried different variations such as swapping the order of arguments, adding "/O" to the switch, removing the "=" -- nothing seems to work.

---

<div class="post-metadata">

**Author:** ![ThioJoe](https://resource.dopus.com/user_avatar/resource.dopus.com/thiojoe/32/42549_2.png) [@ThioJoe](https://resource.dopus.com/u/ThioJoe)\
**Post date:** [July 5, 2024, 8:13pm UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677/2 "2024-07-05T20:13:17Z")

</div>

Can you post the whole script? It would be easier for me to try some things

Edit: Actually try removing the space in the argument template like this:  
`ARTIST/K,REPLACE/S`

I've ran into that issue before. It also seems to fix it at least when I tested a slightly modified user command version of your code:

```jscript
function OnClick(clickData)
{
	var tag_to_add;
	if (clickData.func.args.got_arg.ARTIST) {
		var tag_to_add = clickData.func.args.ARTIST;
		DOpus.Output("Tag to add: " + tag_to_add);
	}
	else {
		DOpus.output("ERROR: no artist argument found");
		return;
	}
}

```

@Leo If I'm correct that argument templates aren't supposed to have spaces in them, it might be worth adding a mention about that [in the wiki](https://docs.dopus.com/doku.php?id=customize:the_customize_dialog:user_commands&s%5B%5D=template)

---

<div class="post-metadata">

**Author:** ![AstoriaBoy](https://resource.dopus.com/letter_avatar_proxy/v4/letter/a/58f4c7/32.png) [@AstoriaBoy](https://resource.dopus.com/u/AstoriaBoy)\
**Post date:** [July 5, 2024, 8:26pm UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677/3 "2024-07-05T20:26:17Z")

</div>

Wow, that was it. Never thought it might be a space issue.

Thanks!

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [July 5, 2024, 9:42pm UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677/4 "2024-07-05T21:42:12Z")

</div>

> [@ThioJoe](#):
>
> @Leo If I'm correct that argument templates aren't supposed to have spaces in them, it might be worth adding a mention about that [in the wiki](https://docs.dopus.com/doku.php?id=customize:the_customize_dialog:user_commands&s%5B%5D=template)

Need to look in more detail but we might be able to make spaces in templates work or filter them out automatically. If not, we'll add a note to the docs.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [July 5, 2024, 11:44pm UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677/5 "2024-07-05T23:44:19Z")

</div>

That's done for 13.7.6 when it comes out.

---

<div class="post-metadata">

**Author:** ![ThioJoe](https://resource.dopus.com/user_avatar/resource.dopus.com/thiojoe/32/42549_2.png) [@ThioJoe](https://resource.dopus.com/u/ThioJoe)\
**Post date:** [July 6, 2024, 12:23am UTC](https://resource.dopus.com/t/switch-argument-for-command-template/51677/6 "2024-07-06T00:23:19Z")

</div>

Ah awesome
