Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bricklib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export const VERSION = '0.1.0-beta';

/* modules */
export { default as config } from './config.js';
export * as args from './args/index.js';
export * as command from './command.js';
export * as database from './database.js';
export * as events from './events.js';
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { FormCancelationReason } from '@minecraft/server-ui';
import * as bricklib from './bricklib/index.js';
import * as gatepass from './gatepass/index.js';
import * as sift from './sift/index.js';

/* load plugins */
bricklib.plugin.loadPlugin('gatepass');
const load = bricklib.plugin.loadPlugin;
load('gatepass');
load('sift');


const mgr = new bricklib.command.CommandManager();
Expand All @@ -23,12 +26,12 @@ const def = {
args: [
{
id: 'text',
type: bricklib.args.parsers.variadic(bricklib.args.parsers.string()),
type: sift.parsers.variadic(sift.parsers.string()),
}
]
};

mgr.registerCommand(...bricklib.args.makeCommand(def, (args, src) => {
mgr.registerCommand(...sift.makeCommand(def, (args, src) => {
gatepass.assertPermission('chat.echo', src);
src.sendMessage(args.text.join(' '));
return 0;
Expand Down
8 changes: 4 additions & 4 deletions src/bricklib/args/defs.ts → src/sift/defs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type * as bricklib from '../bricklib/index.js';
import type { ArgTokenStream } from './tokens.js';
import type { RawString } from '../rawtext.js';

/**
* A command argument parser.
Expand All @@ -17,7 +17,7 @@ export type ParseResult<T extends {} = Record<PropertyKey, any>> = T;
export interface CmdArgument<T = any>
{
id: PropertyKey,
help?: string | RawString,
help?: string | bricklib.rawtext.RawString,
name?: string,

type: TypeParser<T>,
Expand All @@ -33,7 +33,7 @@ export interface CmdArgument<T = any>
export interface CmdOption
{
id: PropertyKey,
help?: string | RawString,
help?: string | bricklib.rawtext.RawString,

long?: string[],
short?: string,
Expand All @@ -46,7 +46,7 @@ export interface CmdOption
export interface CmdVerb
{
id: PropertyKey,
help?: string | RawString,
help?: string | bricklib.rawtext.RawString,

name: string,
aliases?: string[],
Expand Down
27 changes: 20 additions & 7 deletions src/bricklib/args/index.ts → src/sift/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
/**
* Sift -- A flexible command parser for bricklib.
* This plugin is part of the bricklib project.
*/

/* TODO: help-text gen, cmd builder, and more type parsers... */

import * as bricklib from '../bricklib/index.js';
import { Player } from '@minecraft/server';
import { CommandCallback, CommandManager } from '../command.js';
import { parseVerb } from './parser.js';
import { ArgTokenStream } from './tokens.js';
import type { CmdVerb, ParseResult } from './defs.ts';


export type * from './defs.ts';
export * from './parser.js';
export * from './tokens.js';
export * as parsers from './types.js';

bricklib.plugin.newPlugin('sift', () => {
/* no-op */
});


/**
* Parse a custom command.
* @param def The command parsing definition.
Expand All @@ -25,25 +38,25 @@ export function parseCommand(def: CmdVerb, args: string[]): ParseResult

/**
* Make a command def that you can pass to
* {@link CommandManager.registerCommand}.
* {@link bricklib.command.CommandManager.registerCommand}.
* @param def The command definition.
* @param fn The callback.
* @returns Array of args.
* @example
* ```ts
* import * as bricklib from './bricklib/index.js';
* import * as sift from './sift/index.js';
* const def = {
* id: 'echo',
* name: 'echo',
* args: [
* {
* id: 'text',
* type: bricklib.args.parsers.string(),
* type: sift.parsers.string(),
* }
* ]
* };
*
* mgr.registerCommand(...bricklib.args.makeCommand(def, (args, src) => {
* mgr.registerCommand(...sift.makeCommand(def, (args, src) => {
* src.sendMessage(args.text);
* return 0;
* }));
Expand All @@ -52,9 +65,9 @@ export function parseCommand(def: CmdVerb, args: string[]): ParseResult
export function makeCommand<T = any>(
def: CmdVerb,
fn: (args: ParseResult<T>, src: Player) => number
): [string[], CommandCallback]
): [string[], bricklib.command.CommandCallback]
{
const out: [string[], CommandCallback] = [null, null];
const out: [string[], bricklib.command.CommandCallback] = [null, null];
out[0] = [def.name];
if (def.aliases)
out[0] = out[0].concat(def.aliases);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.