Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed args#restResult including leading space #531

Merged
merged 5 commits into from Sep 21, 2022

Conversation

BenSegal855
Copy link
Contributor

@BenSegal855 BenSegal855 commented Sep 17, 2022

This PR removes the leading space when using Args#rest() and Args#restResult() on arguments after the first one. This was achieved by removing the insertion of the paramater.leading value on the first reduction done by Array#reduce(), but keeping it for all others (if it isn't kept, the result would have no spaces kindalikethis). Test images and the code used to generate the images are below. I also added *.tgz to .gitingore as that was generated when I used yarn pack to test the changes.

Before

image

After

image

Test command file used
import { ApplyOptions } from '@sapphire/decorators';
import type { Args } from '@sapphire/framework';
import { send } from '@sapphire/plugin-editable-commands';
import { Subcommand } from '@sapphire/plugin-subcommands';
import type { Message } from 'discord.js';

@ApplyOptions<Subcommand.Options>({
  aliases: ['cws'],
  description: 'A basic command with some subcommands',
  subcommands: [
  	{
  		name: 'show',
  		messageRun: 'sShow'
  	},
  	{
  		name: 'group',
  		type: 'group',
  		entries: [
  			{ name: 'show', messageRun: 'gShow'}
  		]
  	}
  ]
})
export class UserCommand extends Subcommand {

  public async sShow(message: Message, args: Args) {
  	return send(message, `Normal subcommand args:\`\`\`${await args.rest('string')}\`\`\``);
  }

  public async gShow(message: Message, args: Args) {
  	return send(message, `Group subcommand args:\`\`\`${await args.rest('string')}\`\`\``);
  }
}

This PR closes #529

src/lib/parsers/Args.ts Outdated Show resolved Hide resolved
@BenSegal855 BenSegal855 requested review from kyranet and removed request for favna and vladfrangu September 18, 2022 16:16
kyranet
kyranet previously approved these changes Sep 18, 2022
src/lib/parsers/Args.ts Outdated Show resolved Hide resolved
Co-authored-by: Jeroen Claassens <jeroen.claassens@live.nl>
@BenSegal855 BenSegal855 requested review from kyranet and favna and removed request for kyranet and favna September 20, 2022 20:59
@favna favna changed the title Fix args#restResult fix: fixed args#restResult including leading space Sep 21, 2022
@favna favna merged commit 3e560c6 into sapphiredev:main Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

bug: Calling Args#rest will include leading space
4 participants