New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@effect/cli

Package Overview
Dependencies
Maintainers
3
Versions
359
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/cli - npm Package Compare versions

Comparing version 0.0.0-snapshot-ca74efb to 0.0.0-snapshot-e8c7625

41

dist/cjs/Command.js

@@ -6,3 +6,3 @@ "use strict";

});
exports.withSubcommands = exports.withDescription = exports.run = exports.prompt = exports.mapDescriptor = exports.makeUnit = exports.makeHelp = exports.make = exports.fromDescriptorUnit = exports.fromDescriptorHelp = exports.fromDescriptor = exports.TypeId = void 0;
exports.wizard = exports.withSubcommands = exports.withDescription = exports.run = exports.prompt = exports.make = exports.getZshCompletions = exports.getUsage = exports.getSubcommands = exports.getNames = exports.getHelp = exports.getFishCompletions = exports.getBashCompletions = exports.fromDescriptor = exports.TypeId = void 0;
var Internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/command.js"));

@@ -46,34 +46,44 @@ function _getRequireWildcardCache(e) {

* @since 1.0.0
* @category constructors
* @category accessors
*/
const fromDescriptorHelp = exports.fromDescriptorHelp = Internal.fromDescriptorHelp;
const getHelp = exports.getHelp = Internal.getHelp;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
const fromDescriptorUnit = exports.fromDescriptorUnit = Internal.fromDescriptorUnit;
const getNames = exports.getNames = Internal.getNames;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
const make = exports.make = Internal.make;
const getBashCompletions = exports.getBashCompletions = Internal.getBashCompletions;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
const makeHelp = exports.makeHelp = Internal.makeHelp;
const getFishCompletions = exports.getFishCompletions = Internal.getFishCompletions;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
const makeUnit = exports.makeUnit = Internal.makeUnit;
const getZshCompletions = exports.getZshCompletions = Internal.getZshCompletions;
/**
* @since 1.0.0
* @category combinators
* @category accessors
*/
const mapDescriptor = exports.mapDescriptor = Internal.mapDescriptor;
const getSubcommands = exports.getSubcommands = Internal.getSubcommands;
/**
* @since 1.0.0
* @category accessors
*/
const getUsage = exports.getUsage = Internal.getUsage;
/**
* @since 1.0.0
* @category constructors
*/
const make = exports.make = Internal.make;
/**
* @since 1.0.0
* @category constructors
*/
const prompt = exports.prompt = Internal.prompt;

@@ -92,2 +102,7 @@ /**

* @since 1.0.0
* @category accessors
*/
const wizard = exports.wizard = Internal.wizard;
/**
* @since 1.0.0
* @category conversions

@@ -94,0 +109,0 @@ */

@@ -6,3 +6,3 @@ "use strict";

});
exports.wizard = exports.withSubcommands = exports.withDescription = exports.prompt = exports.parse = exports.orElseEither = exports.orElse = exports.mapOrFail = exports.map = exports.make = exports.getZshCompletions = exports.getUsage = exports.getSubcommands = exports.getNames = exports.getHelp = exports.getFishCompletions = exports.getBashCompletions = exports.TypeId = void 0;
exports.wizard = exports.withSubcommands = exports.withDescription = exports.prompt = exports.parse = exports.mapOrFail = exports.map = exports.make = exports.getZshCompletions = exports.getUsage = exports.getSubcommands = exports.getNames = exports.getHelp = exports.getFishCompletions = exports.getBashCompletions = exports.TypeId = void 0;
var Internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/commandDescriptor.js"));

@@ -88,12 +88,2 @@ function _getRequireWildcardCache(e) {

*/
const orElse = exports.orElse = Internal.orElse;
/**
* @since 1.0.0
* @category combinators
*/
const orElseEither = exports.orElseEither = Internal.orElseEither;
/**
* @since 1.0.0
* @category combinators
*/
const parse = exports.parse = Internal.parse;

@@ -100,0 +90,0 @@ /**

@@ -6,3 +6,3 @@ "use strict";

});
exports.weak = exports.uri = exports.text = exports.strong = exports.spans = exports.space = exports.isWeak = exports.isUri = exports.isText = exports.isStrong = exports.isSequence = exports.isError = exports.error = exports.empty = exports.concat = exports.code = void 0;
exports.weak = exports.uri = exports.text = exports.strong = exports.spans = exports.space = exports.isWeak = exports.isUri = exports.isText = exports.isStrong = exports.isSequence = exports.error = exports.empty = exports.concat = exports.code = void 0;
var InternalSpan = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../internal/helpDoc/span.js"));

@@ -36,13 +36,4 @@ function _getRequireWildcardCache(e) {

* @since 1.0.0
*/
/**
* @since 1.0.0
* @category refinements
*/
const isError = exports.isError = InternalSpan.isError;
/**
* @since 1.0.0
* @category refinements
*/
const isSequence = exports.isSequence = InternalSpan.isSequence;

@@ -49,0 +40,0 @@ /**

@@ -490,3 +490,2 @@ "use strict";

};
const wizardHeader = /*#__PURE__*/InternalHelpDoc.p("ARG WIZARD");
const wizardInternal = (self, config) => {

@@ -500,7 +499,7 @@ switch (self._tag) {

{
const help = InternalHelpDoc.sequence(wizardHeader, getHelpInternal(self));
return Console.log().pipe(Effect.zipRight(InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap(input => {
const help = getHelpInternal(self);
return InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(input => {
const args = ReadonlyArray.of(input);
return validateInternal(self, args, config).pipe(Effect.as(args));
}))));
}));
}

@@ -518,8 +517,8 @@ case "Map":

const repeatHelp = InternalHelpDoc.p("How many times should this argument should be repeated?");
const message = (0, _Function.pipe)(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self)), InternalHelpDoc.sequence(repeatHelp));
return Console.log().pipe(Effect.zipRight(InternalNumberPrompt.integer({
const message = (0, _Function.pipe)(getHelpInternal(self), InternalHelpDoc.sequence(repeatHelp));
return InternalNumberPrompt.integer({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
min: getMinSizeInternal(self),
max: getMaxSizeInternal(self)
})), Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.args, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)), Effect.tap(args => validateInternal(self, args, config)))))));
}).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.args, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)), Effect.tap(args => validateInternal(self, args, config)))))));
}

@@ -529,4 +528,4 @@ case "WithDefault":

const defaultHelp = InternalHelpDoc.p(`This argument is optional - use the default?`);
const message = (0, _Function.pipe)(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self.args)), InternalHelpDoc.sequence(defaultHelp));
return Console.log().pipe(Effect.zipRight(InternalSelectPrompt.select({
const message = (0, _Function.pipe)(getHelpInternal(self.args), InternalHelpDoc.sequence(defaultHelp));
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),

@@ -540,3 +539,3 @@ choices: [{

}]
})), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.args, config)));
}).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.args, config)));
}

@@ -543,0 +542,0 @@ }

@@ -7,2 +7,3 @@ "use strict";

exports.run = exports.make = void 0;
var Color = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/printer-ansi/Color"));
var Console = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Console"));

@@ -128,9 +129,17 @@ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Context"));

{
const summary = InternalSpan.isEmpty(self.summary) ? InternalSpan.empty : InternalSpan.spans([InternalSpan.space, InternalSpan.text("--"), InternalSpan.space, self.summary]);
const instructions = InternalHelpDoc.sequence(InternalHelpDoc.p(InternalSpan.spans([InternalSpan.text("The wizard mode will assist you with constructing commands for"), InternalSpan.space, InternalSpan.code(`${self.name} (${self.version})`), InternalSpan.text(".")])), InternalHelpDoc.p("Please answer all prompts provided by the wizard."));
const description = InternalHelpDoc.descriptionList([[InternalSpan.text("Instructions"), instructions]]);
const header = InternalHelpDoc.h1(InternalSpan.spans([InternalSpan.code("Wizard Mode for CLI Application:"), InternalSpan.space, InternalSpan.code(self.name), InternalSpan.space, InternalSpan.code(`(${self.version})`), summary]));
const help = InternalHelpDoc.sequence(header, description);
const text = InternalHelpDoc.toAnsiText(help).trimEnd();
return Console.log(text).pipe(Effect.zipRight(InternalCommand.wizard(builtIn.command, config)), Effect.tap(args => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args)))));
const commandNames = ReadonlyArray.fromIterable(InternalCommand.getNames(self.command));
if (ReadonlyArray.isNonEmptyReadonlyArray(commandNames)) {
const programName = ReadonlyArray.headNonEmpty(commandNames);
const summary = InternalSpan.isEmpty(self.summary) ? InternalSpan.empty : InternalSpan.spans([InternalSpan.space, InternalSpan.text("--"), InternalSpan.space, self.summary]);
const instructions = InternalHelpDoc.sequence(InternalHelpDoc.p(InternalSpan.spans([InternalSpan.text("The wizard mode will assist you with constructing commands for"), InternalSpan.space, InternalSpan.code(`${self.name} (${self.version})`), InternalSpan.text(".")])), InternalHelpDoc.p("Please answer all prompts provided by the wizard."));
const description = InternalHelpDoc.descriptionList([[InternalSpan.text("Instructions"), instructions]]);
const header = InternalHelpDoc.h1(InternalSpan.spans([InternalSpan.code("Wizard Mode for CLI Application:"), InternalSpan.space, InternalSpan.code(self.name), InternalSpan.space, InternalSpan.code(`(${self.version})`), summary]));
const help = InternalHelpDoc.sequence(header, description);
const text = InternalHelpDoc.toAnsiText(help);
return Console.log(text).pipe(Effect.zipRight(InternalCommand.wizard(builtIn.command, programName, config)), Effect.tap(args => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args)))), Effect.catchTag("QuitException", () => {
const message = InternalHelpDoc.p(InternalSpan.error("\n\nQuitting wizard mode..."));
return Console.log(InternalHelpDoc.toAnsiText(message));
}));
}
throw new Error("[BUG]: BuiltInOptions.showWizard - received empty list of command names");
}

@@ -183,5 +192,5 @@ case "ShowVersion":

const params = (0, _Function.pipe)(ReadonlyArray.filter(args, param => param.length > 0), ReadonlyArray.join(" "));
const executeMsg = InternalSpan.weak("You may now execute your command directly with the following options and arguments:");
return InternalHelpDoc.blocks([InternalHelpDoc.p(""), InternalHelpDoc.p(InternalSpan.strong(InternalSpan.code("Wizard Mode Complete!"))), InternalHelpDoc.p(executeMsg), InternalHelpDoc.p(InternalSpan.code(` ${params}`))]);
const executeMsg = InternalSpan.text("You may now execute your command directly with the following options and arguments:");
return InternalHelpDoc.blocks([InternalHelpDoc.p(InternalSpan.strong(InternalSpan.code("Wizard Mode Complete!"))), InternalHelpDoc.p(executeMsg), InternalHelpDoc.p(InternalSpan.concat(InternalSpan.text(" "), InternalSpan.highlight(params, Color.cyan)))]);
};
//# sourceMappingURL=cliApp.js.map

@@ -6,3 +6,3 @@ "use strict";

});
exports.withSubcommands = exports.withDescription = exports.run = exports.prompt = exports.mapDescriptor = exports.mapBoth = exports.makeUnit = exports.makeHelp = exports.make = exports.fromDescriptorUnit = exports.fromDescriptorHelp = exports.fromDescriptor = exports.TypeId = void 0;
exports.wizard = exports.withSubcommands = exports.withDescription = exports.run = exports.prompt = exports.make = exports.getZshCompletions = exports.getUsage = exports.getSubcommands = exports.getNames = exports.getHelp = exports.getFishCompletions = exports.getBashCompletions = exports.fromDescriptor = exports.TypeId = void 0;
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Context"));

@@ -130,12 +130,6 @@ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));

/** @internal */
const fromDescriptor = exports.fromDescriptor = /*#__PURE__*/(0, _Function.dual)(2, (descriptor, handler) => makeProto(descriptor, handler));
/** @internal */
const fromDescriptorUnit = descriptor => makeProto(descriptor, _ => Effect.unit);
/** @internal */
exports.fromDescriptorUnit = fromDescriptorUnit;
const fromDescriptorHelp = descriptor => {
const self = makeProto(descriptor, _ => Effect.fail(ValidationError.helpRequested(getDescriptor(self))));
const fromDescriptor = exports.fromDescriptor = /*#__PURE__*/(0, _Function.dual)(args => InternalDescriptor.isCommand(args[0]), (descriptor, handler) => {
const self = makeProto(descriptor, handler ?? (_ => Effect.failSync(() => ValidationError.helpRequested(getDescriptor(self)))));
return self;
};
exports.fromDescriptorHelp = fromDescriptorHelp;
});
const makeDescriptor = (name, config) => {

@@ -153,15 +147,27 @@ const {

/** @internal */
const make = (name, config, handler) => makeProto(makeDescriptor(name, config), handler);
const make = (name, config = {}, handler) => fromDescriptor(makeDescriptor(name, config), handler);
/** @internal */
exports.make = make;
const makeUnit = (name, config = {}) => fromDescriptorUnit(makeDescriptor(name, config));
const getHelp = self => InternalDescriptor.getHelp(self.descriptor);
/** @internal */
exports.makeUnit = makeUnit;
const makeHelp = (name, config = {}) => fromDescriptorHelp(makeDescriptor(name, config));
exports.getHelp = getHelp;
const getNames = self => InternalDescriptor.getNames(self.descriptor);
/** @internal */
exports.makeHelp = makeHelp;
const mapDescriptor = exports.mapDescriptor = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => makeProto(f(getDescriptor(self)), self.handler, self.tag));
exports.getNames = getNames;
const getBashCompletions = (self, programName) => InternalDescriptor.getBashCompletions(self.descriptor, programName);
/** @internal */
const mapBoth = exports.mapBoth = /*#__PURE__*/(0, _Function.dual)(3, (self, f, g) => makeProto(f(getDescriptor(self)), _ => self.handler(g(_)), self.tag));
exports.getBashCompletions = getBashCompletions;
const getFishCompletions = (self, programName) => InternalDescriptor.getFishCompletions(self.descriptor, programName);
/** @internal */
exports.getFishCompletions = getFishCompletions;
const getZshCompletions = (self, programName) => InternalDescriptor.getZshCompletions(self.descriptor, programName);
/** @internal */
exports.getZshCompletions = getZshCompletions;
const getSubcommands = self => InternalDescriptor.getSubcommands(self.descriptor);
/** @internal */
exports.getSubcommands = getSubcommands;
const getUsage = self => InternalDescriptor.getUsage(self.descriptor);
exports.getUsage = getUsage;
const mapDescriptor = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => makeProto(f(getDescriptor(self)), self.handler, self.tag));
/** @internal */
const prompt = (name, prompt, handler) => makeProto(InternalDescriptor.map(InternalDescriptor.prompt(name, prompt), _ => _.value), handler);

@@ -188,2 +194,4 @@ /** @internal */

/** @internal */
const wizard = exports.wizard = /*#__PURE__*/(0, _Function.dual)(3, (self, rootCommand, config) => InternalDescriptor.wizard(self.descriptor, rootCommand, config));
/** @internal */
const run = exports.run = /*#__PURE__*/(0, _Function.dual)(2, (self, config) => {

@@ -190,0 +198,0 @@ const app = InternalCliApp.make({

@@ -7,2 +7,3 @@ "use strict";

exports.wizard = exports.withSubcommands = exports.withDescription = exports.prompt = exports.parse = exports.orElseEither = exports.orElse = exports.mapOrFail = exports.map = exports.make = exports.isSubcommands = exports.isStandard = exports.isOrElse = exports.isMap = exports.isGetUserInput = exports.isCommand = exports.helpRequestedError = exports.getZshCompletions = exports.getUsage = exports.getSubcommands = exports.getNames = exports.getHelp = exports.getFishCompletions = exports.getBashCompletions = exports.TypeId = void 0;
var Color = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/printer-ansi/Color"));
var Console = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Console"));

@@ -18,2 +19,3 @@ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));

var ReadonlyArray = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/ReadonlyArray"));
var Ref = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Ref"));
var SynchronizedRef = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/SynchronizedRef"));

@@ -177,3 +179,3 @@ var HelpDoc = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../HelpDoc.js"));

/** @internal */
const wizard = exports.wizard = /*#__PURE__*/(0, _Function.dual)(2, (self, config) => wizardInternal(self, config));
const wizard = exports.wizard = /*#__PURE__*/(0, _Function.dual)(3, (self, rootCommand, config) => wizardInternal(self, rootCommand, config));
// =============================================================================

@@ -389,3 +391,3 @@ // Internals

{
return InternalPrompt.run(self.prompt).pipe(Effect.map(value => InternalCommandDirective.userDefined(ReadonlyArray.drop(args, 1), {
return InternalPrompt.run(self.prompt).pipe(Effect.catchTag("QuitException", e => Effect.die(e)), Effect.map(value => InternalCommandDirective.userDefined(ReadonlyArray.drop(args, 1), {
name: self.name,

@@ -528,12 +530,37 @@ value

};
const wizardInternal = (self, config) => {
const loop = self => {
const argsWizardHeader = /*#__PURE__*/InternalSpan.code("Args Wizard - ");
const optionsWizardHeader = /*#__PURE__*/InternalSpan.code("Options Wizard - ");
const wizardInternal = (self, rootCommand, config) => {
const loop = (self, commandLineRef) => {
switch (self._tag) {
case "SingleCommandWizard":
{
const optionsWizard = isStandard(self.command) ? InternalOptions.wizard(self.command.options, config) : Effect.succeed(ReadonlyArray.empty());
const argsWizard = isStandard(self.command) ? InternalArgs.wizard(self.command.args, config) : Effect.succeed(ReadonlyArray.empty());
const help = InternalHelpDoc.p((0, _Function.pipe)(InternalSpan.text("\n"), InternalSpan.concat(InternalSpan.strong(InternalSpan.code("COMMAND:"))), InternalSpan.concat(InternalSpan.space), InternalSpan.concat(InternalSpan.code(self.command.name))));
const message = InternalHelpDoc.toAnsiText(help);
return Console.log(message).pipe(Effect.zipRight(Effect.zipWith(optionsWizard, argsWizard, (options, args) => (0, _Function.pipe)(ReadonlyArray.appendAll(options, args), ReadonlyArray.prepend(self.command.name)))));
return Effect.gen(function* (_) {
const logCurrentCommand = Ref.get(commandLineRef).pipe(Effect.flatMap(commandLine => {
const currentCommand = InternalHelpDoc.p((0, _Function.pipe)(InternalSpan.strong(InternalSpan.highlight("COMMAND:", Color.cyan)), InternalSpan.concat(InternalSpan.space), InternalSpan.concat(InternalSpan.highlight(ReadonlyArray.join(commandLine, " "), Color.magenta))));
return Console.log(InternalHelpDoc.toAnsiText(currentCommand));
}));
if (isStandard(self.command)) {
// Log the current command line arguments
yield* _(logCurrentCommand);
const commandName = InternalSpan.highlight(self.command.name, Color.magenta);
// If the command has options, run the wizard for them
if (!InternalOptions.isEmpty(self.command.options)) {
const message = InternalHelpDoc.p(InternalSpan.concat(optionsWizardHeader, commandName));
yield* _(Console.log(InternalHelpDoc.toAnsiText(message)));
const options = yield* _(InternalOptions.wizard(self.command.options, config));
yield* _(Ref.updateAndGet(commandLineRef, ReadonlyArray.appendAll(options)));
yield* _(logCurrentCommand);
}
// If the command has args, run the wizard for them
if (!InternalArgs.isEmpty(self.command.args)) {
const message = InternalHelpDoc.p(InternalSpan.concat(argsWizardHeader, commandName));
yield* _(Console.log(InternalHelpDoc.toAnsiText(message)));
const options = yield* _(InternalArgs.wizard(self.command.args, config));
yield* _(Ref.updateAndGet(commandLineRef, ReadonlyArray.appendAll(options)));
yield* _(logCurrentCommand);
}
}
return yield* _(Ref.get(commandLineRef));
});
}

@@ -544,3 +571,3 @@ case "AlternativeCommandWizard":

title,
value
value: [title, value]
});

@@ -564,11 +591,11 @@ const choices = self.alternatives.map(alternative => {

choices
}).pipe(Effect.flatMap(nextSequence => loop(nextSequence)));
}).pipe(Effect.tap(([name]) => Ref.update(commandLineRef, ReadonlyArray.append(name))), Effect.zipLeft(Console.log()), Effect.flatMap(([, nextSequence]) => loop(nextSequence, commandLineRef)));
}
case "SubcommandWizard":
{
return Effect.zipWith(loop(self.parent), loop(self.child), (parent, child) => ReadonlyArray.appendAll(parent, child));
return loop(self.parent, commandLineRef).pipe(Effect.zipRight(loop(self.child, commandLineRef)));
}
}
};
return loop(getWizardCommandSequence(self));
return Ref.make(ReadonlyArray.of(rootCommand)).pipe(Effect.flatMap(commandLineRef => loop(getWizardCommandSequence(self), commandLineRef).pipe(Effect.zipRight(Ref.get(commandLineRef)))));
};

@@ -575,0 +602,0 @@ /**

@@ -6,3 +6,3 @@ "use strict";

});
exports.weak = exports.uri = exports.toAnsiDoc = exports.text = exports.strong = exports.spans = exports.space = exports.size = exports.isWeak = exports.isUri = exports.isText = exports.isStrong = exports.isSequence = exports.isError = exports.isEmpty = exports.isCode = exports.getText = exports.error = exports.empty = exports.concat = exports.code = void 0;
exports.weak = exports.uri = exports.toAnsiDoc = exports.text = exports.strong = exports.spans = exports.space = exports.size = exports.isWeak = exports.isUri = exports.isText = exports.isStrong = exports.isSequence = exports.isEmpty = exports.highlight = exports.getText = exports.error = exports.empty = exports.concat = exports.code = void 0;
var AnsiStyle = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/printer-ansi/AnsiStyle"));

@@ -49,20 +49,15 @@ var Color = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/printer-ansi/Color"));

/** @internal */
const code = value => ({
_tag: "Code",
value
});
const code = value => highlight(value, Color.white);
/** @internal */
exports.code = code;
const error = value => ({
_tag: "Error",
value: typeof value === "string" ? text(value) : value
});
const error = value => highlight(value, Color.red);
/** @internal */
exports.error = error;
const weak = value => ({
_tag: "Weak",
value: typeof value === "string" ? text(value) : value
const highlight = (value, color) => ({
_tag: "Highlight",
value: typeof value === "string" ? text(value) : value,
color
});
/** @internal */
exports.weak = weak;
exports.highlight = highlight;
const strong = value => ({

@@ -80,8 +75,8 @@ _tag: "Strong",

exports.uri = uri;
const isCode = self => self._tag === "Code";
const weak = value => ({
_tag: "Weak",
value: typeof value === "string" ? text(value) : value
});
/** @internal */
exports.isCode = isCode;
const isError = self => self._tag === "Error";
/** @internal */
exports.isError = isError;
exports.weak = weak;
const isSequence = self => self._tag === "Sequence";

@@ -110,3 +105,2 @@ /** @internal */

case "Text":
case "Code":
case "URI":

@@ -116,3 +110,3 @@ {

}
case "Error":
case "Highlight":
case "Weak":

@@ -145,3 +139,2 @@ case "Strong":

switch (self._tag) {
case "Code":
case "Text":

@@ -152,3 +145,3 @@ case "URI":

}
case "Error":
case "Highlight":
case "Strong":

@@ -169,22 +162,18 @@ case "Weak":

switch (self._tag) {
case "Text":
case "Highlight":
{
return Doc.text(self.value);
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.color(self.color));
}
case "Code":
case "Sequence":
{
return Doc.annotate(Doc.text(self.value), AnsiStyle.color(Color.white));
return Doc.cat(toAnsiDoc(self.left), toAnsiDoc(self.right));
}
case "Error":
case "Strong":
{
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.color(Color.red));
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.bold);
}
case "Weak":
case "Text":
{
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.dullColor(Color.black));
return Doc.text(self.value);
}
case "Strong":
{
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.bold);
}
case "URI":

@@ -194,5 +183,5 @@ {

}
case "Sequence":
case "Weak":
{
return Doc.cat(toAnsiDoc(self.left), toAnsiDoc(self.right));
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.dullColor(Color.black));
}

@@ -199,0 +188,0 @@ }

@@ -911,3 +911,2 @@ "use strict";

};
const wizardHeader = /*#__PURE__*/InternalHelpDoc.p("Option Wizard");
const wizardInternal = (self, config) => {

@@ -921,20 +920,19 @@ switch (self._tag) {

{
const help = InternalHelpDoc.sequence(wizardHeader, getHelpInternal(self));
return Console.log().pipe(Effect.zipRight(InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap(input => {
const help = getHelpInternal(self);
return InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap(input => {
// There will always be at least one name in names
const args = ReadonlyArray.make(getNames(self)[0], input);
return parseOptions(self, args, config).pipe(Effect.as(args));
}))));
}), Effect.zipLeft(Console.log()));
}
case "KeyValueMap":
{
const optionHelp = InternalHelpDoc.p("Enter `key=value` pairs separated by spaces");
const message = InternalHelpDoc.sequence(wizardHeader, optionHelp);
return Console.log().pipe(Effect.zipRight(InternalListPrompt.list({
const message = InternalHelpDoc.p("Enter `key=value` pairs separated by spaces");
return InternalListPrompt.list({
message: InternalHelpDoc.toAnsiText(message).trim(),
delimiter: " "
})), Effect.flatMap(args => {
}).pipe(Effect.flatMap(args => {
const identifier = Option.getOrElse(getIdentifierInternal(self), () => "");
return parseInternal(self, HashMap.make([identifier, args]), config).pipe(Effect.as(ReadonlyArray.prepend(args, identifier)));
}));
}), Effect.zipLeft(Console.log()));
}

@@ -952,3 +950,3 @@ case "Map":

const alternativeHelp = InternalHelpDoc.p("Select which option you would like to use");
const message = (0, _Function.pipe)(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self)), InternalHelpDoc.sequence(alternativeHelp));
const message = (0, _Function.pipe)(getHelpInternal(self), InternalHelpDoc.sequence(alternativeHelp));
const makeChoice = (title, value) => ({

@@ -959,6 +957,6 @@ title,

const choices = ReadonlyArray.compact([Option.map(getIdentifierInternal(self.left), title => makeChoice(title, self.left)), Option.map(getIdentifierInternal(self.right), title => makeChoice(title, self.right))]);
return Console.log().pipe(Effect.zipRight(InternalSelectPrompt.select({
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
choices
})), Effect.flatMap(option => wizardInternal(option, config)));
}).pipe(Effect.flatMap(option => wizardInternal(option, config)));
}

@@ -968,8 +966,8 @@ case "Variadic":

const repeatHelp = InternalHelpDoc.p("How many times should this argument should be repeated?");
const message = (0, _Function.pipe)(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self)), InternalHelpDoc.sequence(repeatHelp));
return Console.log().pipe(Effect.zipRight(InternalNumberPrompt.integer({
const message = (0, _Function.pipe)(getHelpInternal(self), InternalHelpDoc.sequence(repeatHelp));
return InternalNumberPrompt.integer({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
min: getMinSizeInternal(self),
max: getMaxSizeInternal(self)
})), Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.argumentOption, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)))))));
}).pipe(Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.argumentOption, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)))))));
}

@@ -982,4 +980,4 @@ case "WithDefault":

const defaultHelp = InternalHelpDoc.p(`This option is optional - use the default?`);
const message = (0, _Function.pipe)(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self.options)), InternalHelpDoc.sequence(defaultHelp));
return Console.log().pipe(Effect.zipRight(InternalSelectPrompt.select({
const message = (0, _Function.pipe)(getHelpInternal(self.options), InternalHelpDoc.sequence(defaultHelp));
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),

@@ -993,3 +991,3 @@ choices: [{

}]
})), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.options, config)));
}).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.options, config)));
}

@@ -996,0 +994,0 @@ }

@@ -373,3 +373,3 @@ "use strict";

inactive: "false"
}).pipe(InternalPrompt.map(bool => bool));
}).pipe(InternalPrompt.map(bool => `${bool}`));
}

@@ -376,0 +376,0 @@ case "Choice":

@@ -114,3 +114,3 @@ "use strict";

return Effect.all([Ref.make(Option.none()), Ref.make(op.initialState)]).pipe(Effect.flatMap(([prevStateRef, nextStateRef]) => {
const loop = action => Effect.all([Ref.get(prevStateRef), Ref.get(nextStateRef)]).pipe(Effect.flatMap(([prevState, nextState]) => op.render(prevState, nextState, action).pipe(Effect.flatMap(msg => Effect.orDie(terminal.display(msg))), Effect.zipRight(terminal.readInput), Effect.catchTag("QuitException", e => Effect.die(e)), Effect.flatMap(input => op.process(input, nextState)), Effect.flatMap(action => {
const loop = action => Effect.all([Ref.get(prevStateRef), Ref.get(nextStateRef)]).pipe(Effect.flatMap(([prevState, nextState]) => op.render(prevState, nextState, action).pipe(Effect.flatMap(msg => Effect.orDie(terminal.display(msg))), Effect.zipRight(terminal.readInput), Effect.flatMap(input => op.process(input, nextState)), Effect.flatMap(action => {
switch (action._tag) {

@@ -117,0 +117,0 @@ case "Beep":

@@ -5,3 +5,3 @@ /**

import type { FileSystem } from "@effect/platform/FileSystem";
import type { Terminal } from "@effect/platform/Terminal";
import type { QuitException, Terminal } from "@effect/platform/Terminal";
import type { Effect } from "effect/Effect";

@@ -294,4 +294,4 @@ import type { Either } from "effect/Either";

export declare const withDefault: {
<A>(fallback: A): (self: Args<A>) => Args<A>;
<A>(self: Args<A>, fallback: A): Args<A>;
<const B>(fallback: B): <A>(self: Args<A>) => Args<B | A>;
<A, const B>(self: Args<A>, fallback: B): Args<A | B>;
};

@@ -311,5 +311,5 @@ /**

export declare const wizard: {
(config: CliConfig): <A>(self: Args<A>) => Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>;
<A>(self: Args<A>, config: CliConfig): Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>;
(config: CliConfig): <A>(self: Args<A>) => Effect<FileSystem | Terminal, ValidationError | QuitException, ReadonlyArray<string>>;
<A>(self: Args<A>, config: CliConfig): Effect<FileSystem | Terminal, ValidationError | QuitException, ReadonlyArray<string>>;
};
//# sourceMappingURL=Args.d.ts.map
/**
* @since 1.0.0
*/
import type { FileSystem } from "@effect/platform/FileSystem";
import type { QuitException, Terminal } from "@effect/platform/Terminal";
import type { Tag } from "effect/Context";
import type { Effect } from "effect/Effect";
import type { HashMap } from "effect/HashMap";
import type { HashSet } from "effect/HashSet";
import type { Option } from "effect/Option";

@@ -11,2 +15,3 @@ import { type Pipeable } from "effect/Pipeable";

import type { CliApp } from "./CliApp.js";
import type { CliConfig } from "./CliConfig.js";
import type * as Descriptor from "./CommandDescriptor.js";

@@ -17,2 +22,3 @@ import type { HelpDoc } from "./HelpDoc.js";

import type { Prompt } from "./Prompt.js";
import type { Usage } from "./Usage.js";
import type { ValidationError } from "./ValidationError.js";

@@ -100,2 +106,5 @@ /**

export declare const fromDescriptor: {
(): <A extends {
readonly name: string;
}>(command: Descriptor.Command<A>) => Command<A["name"], never, never, A>;
<A extends {

@@ -106,2 +115,5 @@ readonly name: string;

readonly name: string;
}>(descriptor: Descriptor.Command<A>): Command<A["name"], never, never, A>;
<A extends {
readonly name: string;
}, R, E>(descriptor: Descriptor.Command<A>, handler: (_: A) => Effect<R, E, void>): Command<A["name"], R, E, A>;

@@ -111,46 +123,43 @@ };

* @since 1.0.0
* @category constructors
* @category accessors
*/
export declare const fromDescriptorHelp: <A extends {
readonly name: string;
}>(descriptor: Descriptor.Command<A>) => Command<A["name"], never, ValidationError, A>;
export declare const getHelp: <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => HelpDoc;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export declare const fromDescriptorUnit: <A extends {
readonly name: string;
}>(descriptor: Descriptor.Command<A>) => Command<A["name"], never, never, A>;
export declare const getNames: <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => HashSet<string>;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export declare const make: <Name extends string, const Config extends Command.ConfigBase, R, E>(name: Name, config: Config, handler: (_: Types.Simplify<Command.ParseConfig<Config>>) => Effect<R, E, void>) => Command<Name, R, E, Types.Simplify<Command.ParseConfig<Config>>>;
export declare const getBashCompletions: <Name extends string, R, E, A>(self: Command<Name, R, E, A>, programName: string) => Effect<never, never, ReadonlyArray<string>>;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export declare const makeHelp: {
<Name extends string>(name: Name): Command<Name, never, ValidationError, {}>;
<Name extends string, const Config extends Command.ConfigBase>(name: Name, config: Config): Command<Name, never, ValidationError, Types.Simplify<Types.Simplify<{
readonly [Key in keyof Config]: Command.ParseConfigValue<Config[Key]>;
}>>>;
};
export declare const getFishCompletions: <Name extends string, R, E, A>(self: Command<Name, R, E, A>, programName: string) => Effect<never, never, ReadonlyArray<string>>;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export declare const makeUnit: {
<Name extends string>(name: Name): Command<Name, {}, never, never>;
<Name extends string, const Config extends Command.ConfigBase>(name: Name, config: Config): Command<Name, never, never, Types.Simplify<Types.Simplify<{
readonly [Key in keyof Config]: Command.ParseConfigValue<Config[Key]>;
}>>>;
};
export declare const getZshCompletions: <Name extends string, R, E, A>(self: Command<Name, R, E, A>, programName: string) => Effect<never, never, ReadonlyArray<string>>;
/**
* @since 1.0.0
* @category combinators
* @category accessors
*/
export declare const mapDescriptor: {
<A>(f: (_: Descriptor.Command<A>) => Descriptor.Command<A>): <Name extends string, R, E>(self: Command<Name, R, E, A>) => Command<Name, R, E, A>;
<Name extends string, R, E, A>(self: Command<Name, R, E, A>, f: (_: Descriptor.Command<A>) => Descriptor.Command<A>): Command<Name, R, E, A>;
export declare const getSubcommands: <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => HashMap<string, Descriptor.Command<unknown>>;
/**
* @since 1.0.0
* @category accessors
*/
export declare const getUsage: <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => Usage;
/**
* @since 1.0.0
* @category constructors
*/
export declare const make: {
<Name extends string>(name: Name): Command<Name, never, never, {}>;
<Name extends string, const Config extends Command.ConfigBase>(name: Name, config: Config): Command<Name, never, never, Types.Simplify<Command.ParseConfig<Config>>>;
<Name extends string, const Config extends Command.ConfigBase, R, E>(name: Name, config: Config, handler: (_: Types.Simplify<Command.ParseConfig<Config>>) => Effect<R, E, void>): Command<Name, R, E, Types.Simplify<Command.ParseConfig<Config>>>;
};

@@ -184,2 +193,10 @@ /**

* @since 1.0.0
* @category accessors
*/
export declare const wizard: {
(rootCommand: string, config: CliConfig): <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>;
<Name extends string, R, E, A>(self: Command<Name, R, E, A>, rootCommand: string, config: CliConfig): Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>;
};
/**
* @since 1.0.0
* @category conversions

@@ -186,0 +203,0 @@ */

@@ -5,3 +5,3 @@ /**

import type { FileSystem } from "@effect/platform/FileSystem";
import type { Terminal } from "@effect/platform/Terminal";
import type { QuitException, Terminal } from "@effect/platform/Terminal";
import type { Effect } from "effect/Effect";

@@ -147,18 +147,2 @@ import type { Either } from "effect/Either";

*/
export declare const orElse: {
<B>(that: Command<B>): <A>(self: Command<A>) => Command<A | B>;
<A, B>(self: Command<A>, that: Command<B>): Command<A | B>;
};
/**
* @since 1.0.0
* @category combinators
*/
export declare const orElseEither: {
<B>(that: Command<B>): <A>(self: Command<A>) => Command<Either<A, B>>;
<A, B>(self: Command<A>, that: Command<B>): Command<Either<A, B>>;
};
/**
* @since 1.0.0
* @category combinators
*/
export declare const parse: {

@@ -198,3 +182,3 @@ (args: ReadonlyArray<string>, config: CliConfig): <A>(self: Command<A>) => Effect<FileSystem | Terminal, ValidationError, CommandDirective<A>>;

export declare const withSubcommands: {
<Subcommands extends readonly [
<const Subcommands extends readonly [
readonly [id: unknown, command: Command<any>],

@@ -205,3 +189,3 @@ ...Array<readonly [id: unknown, command: Command<any>]>

}>>>;
<A, Subcommands extends readonly [
<A, const Subcommands extends readonly [
readonly [id: unknown, command: Command<any>],

@@ -218,5 +202,5 @@ ...Array<readonly [id: unknown, command: Command<any>]>

export declare const wizard: {
(config: CliConfig): <A>(self: Command<A>) => Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>;
<A>(self: Command<A>, config: CliConfig): Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>;
(rootCommand: string, config: CliConfig): <A>(self: Command<A>) => Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>;
<A>(self: Command<A>, rootCommand: string, config: CliConfig): Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>;
};
//# sourceMappingURL=CommandDescriptor.d.ts.map
/**
* @since 1.0.0
* @category models
*/
export type Span = Text | Code | Error | Weak | Strong | URI | Sequence;
import type { Color } from "@effect/printer-ansi/Color";
/**

@@ -10,6 +9,3 @@ * @since 1.0.0

*/
export interface Text {
readonly _tag: "Text";
readonly value: string;
}
export type Span = Highlight | Sequence | Strong | Text | URI | Weak;
/**

@@ -19,5 +15,6 @@ * @since 1.0.0

*/
export interface Code {
readonly _tag: "Code";
readonly value: string;
export interface Highlight {
readonly _tag: "Highlight";
readonly value: Span;
readonly color: Color;
}

@@ -28,5 +25,6 @@ /**

*/
export interface Error {
readonly _tag: "Error";
readonly value: Span;
export interface Sequence {
readonly _tag: "Sequence";
readonly left: Span;
readonly right: Span;
}

@@ -37,4 +35,4 @@ /**

*/
export interface Weak {
readonly _tag: "Weak";
export interface Strong {
readonly _tag: "Strong";
readonly value: Span;

@@ -46,5 +44,5 @@ }

*/
export interface Strong {
readonly _tag: "Strong";
readonly value: Span;
export interface Text {
readonly _tag: "Text";
readonly value: string;
}

@@ -63,6 +61,5 @@ /**

*/
export interface Sequence {
readonly _tag: "Sequence";
readonly left: Span;
readonly right: Span;
export interface Weak {
readonly _tag: "Weak";
readonly value: Span;
}

@@ -73,7 +70,2 @@ /**

*/
export declare const isError: (self: Span) => self is Error;
/**
* @since 1.0.0
* @category refinements
*/
export declare const isSequence: (self: Span) => self is Sequence;

@@ -119,3 +111,3 @@ /**

*/
export declare const code: (value: string) => Span;
export declare const code: (value: string | Span) => Span;
/**

@@ -122,0 +114,0 @@ * @since 1.0.0

@@ -5,3 +5,3 @@ /**

import type { FileSystem } from "@effect/platform/FileSystem";
import type { Terminal } from "@effect/platform/Terminal";
import type { QuitException, Terminal } from "@effect/platform/Terminal";
import type { Effect } from "effect/Effect";

@@ -357,4 +357,4 @@ import type { Either } from "effect/Either";

export declare const withDefault: {
<A>(fallback: A): (self: Options<A>) => Options<A>;
<A>(self: Options<A>, fallback: A): Options<A>;
<const B>(fallback: B): <A>(self: Options<A>) => Options<B | A>;
<A, const B>(self: Options<A>, fallback: B): Options<A | B>;
};

@@ -382,5 +382,5 @@ /**

export declare const wizard: {
(config: CliConfig): <A>(self: Options<A>) => Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>;
<A>(self: Options<A>, config: CliConfig): Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>;
(config: CliConfig): <A>(self: Options<A>) => Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>;
<A>(self: Options<A>, config: CliConfig): Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>;
};
//# sourceMappingURL=Options.d.ts.map
/**
* @since 1.0.0
*/
import type { Terminal, UserInput } from "@effect/platform/Terminal";
import type { QuitException, Terminal, UserInput } from "@effect/platform/Terminal";
import type { Effect } from "effect/Effect";

@@ -23,3 +23,3 @@ import type { Option } from "effect/Option";

*/
export interface Prompt<Output> extends Prompt.Variance<Output>, Pipeable, Effect<Terminal, never, Output> {
export interface Prompt<Output> extends Prompt.Variance<Output>, Pipeable, Effect<Terminal, QuitException, Output> {
}

@@ -399,3 +399,3 @@ /**

*/
export declare const run: <Output>(self: Prompt<Output>) => Effect<Terminal, never, Output>;
export declare const run: <Output>(self: Prompt<Output>) => Effect<Terminal, QuitException, Output>;
/**

@@ -402,0 +402,0 @@ * @since 1.0.0

@@ -14,34 +14,44 @@ import * as Internal from "./internal/command.js";

* @since 1.0.0
* @category constructors
* @category accessors
*/
export const fromDescriptorHelp = Internal.fromDescriptorHelp;
export const getHelp = Internal.getHelp;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export const fromDescriptorUnit = Internal.fromDescriptorUnit;
export const getNames = Internal.getNames;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export const make = Internal.make;
export const getBashCompletions = Internal.getBashCompletions;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export const makeHelp = Internal.makeHelp;
export const getFishCompletions = Internal.getFishCompletions;
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export const makeUnit = Internal.makeUnit;
export const getZshCompletions = Internal.getZshCompletions;
/**
* @since 1.0.0
* @category combinators
* @category accessors
*/
export const mapDescriptor = Internal.mapDescriptor;
export const getSubcommands = Internal.getSubcommands;
/**
* @since 1.0.0
* @category accessors
*/
export const getUsage = Internal.getUsage;
/**
* @since 1.0.0
* @category constructors
*/
export const make = Internal.make;
/**
* @since 1.0.0
* @category constructors
*/
export const prompt = Internal.prompt;

@@ -60,2 +70,7 @@ /**

* @since 1.0.0
* @category accessors
*/
export const wizard = Internal.wizard;
/**
* @since 1.0.0
* @category conversions

@@ -62,0 +77,0 @@ */

@@ -56,12 +56,2 @@ import * as Internal from "./internal/commandDescriptor.js";

*/
export const orElse = Internal.orElse;
/**
* @since 1.0.0
* @category combinators
*/
export const orElseEither = Internal.orElseEither;
/**
* @since 1.0.0
* @category combinators
*/
export const parse = Internal.parse;

@@ -68,0 +58,0 @@ /**

@@ -1,4 +0,1 @@

/**
* @since 1.0.0
*/
import * as InternalSpan from "../internal/helpDoc/span.js";

@@ -9,7 +6,2 @@ /**

*/
export const isError = InternalSpan.isError;
/**
* @since 1.0.0
* @category refinements
*/
export const isSequence = InternalSpan.isSequence;

@@ -16,0 +8,0 @@ /**

@@ -436,3 +436,2 @@ import * as Console from "effect/Console";

};
const wizardHeader = /*#__PURE__*/InternalHelpDoc.p("ARG WIZARD");
const wizardInternal = (self, config) => {

@@ -446,7 +445,7 @@ switch (self._tag) {

{
const help = InternalHelpDoc.sequence(wizardHeader, getHelpInternal(self));
return Console.log().pipe(Effect.zipRight(InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap(input => {
const help = getHelpInternal(self);
return InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(input => {
const args = ReadonlyArray.of(input);
return validateInternal(self, args, config).pipe(Effect.as(args));
}))));
}));
}

@@ -464,8 +463,8 @@ case "Map":

const repeatHelp = InternalHelpDoc.p("How many times should this argument should be repeated?");
const message = pipe(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self)), InternalHelpDoc.sequence(repeatHelp));
return Console.log().pipe(Effect.zipRight(InternalNumberPrompt.integer({
const message = pipe(getHelpInternal(self), InternalHelpDoc.sequence(repeatHelp));
return InternalNumberPrompt.integer({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
min: getMinSizeInternal(self),
max: getMaxSizeInternal(self)
})), Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.args, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)), Effect.tap(args => validateInternal(self, args, config)))))));
}).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.args, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)), Effect.tap(args => validateInternal(self, args, config)))))));
}

@@ -475,4 +474,4 @@ case "WithDefault":

const defaultHelp = InternalHelpDoc.p(`This argument is optional - use the default?`);
const message = pipe(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self.args)), InternalHelpDoc.sequence(defaultHelp));
return Console.log().pipe(Effect.zipRight(InternalSelectPrompt.select({
const message = pipe(getHelpInternal(self.args), InternalHelpDoc.sequence(defaultHelp));
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),

@@ -486,3 +485,3 @@ choices: [{

}]
})), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.args, config)));
}).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.args, config)));
}

@@ -489,0 +488,0 @@ }

@@ -0,1 +1,2 @@

import * as Color from "@effect/printer-ansi/Color";
import * as Console from "effect/Console";

@@ -95,9 +96,17 @@ import * as Context from "effect/Context";

{
const summary = InternalSpan.isEmpty(self.summary) ? InternalSpan.empty : InternalSpan.spans([InternalSpan.space, InternalSpan.text("--"), InternalSpan.space, self.summary]);
const instructions = InternalHelpDoc.sequence(InternalHelpDoc.p(InternalSpan.spans([InternalSpan.text("The wizard mode will assist you with constructing commands for"), InternalSpan.space, InternalSpan.code(`${self.name} (${self.version})`), InternalSpan.text(".")])), InternalHelpDoc.p("Please answer all prompts provided by the wizard."));
const description = InternalHelpDoc.descriptionList([[InternalSpan.text("Instructions"), instructions]]);
const header = InternalHelpDoc.h1(InternalSpan.spans([InternalSpan.code("Wizard Mode for CLI Application:"), InternalSpan.space, InternalSpan.code(self.name), InternalSpan.space, InternalSpan.code(`(${self.version})`), summary]));
const help = InternalHelpDoc.sequence(header, description);
const text = InternalHelpDoc.toAnsiText(help).trimEnd();
return Console.log(text).pipe(Effect.zipRight(InternalCommand.wizard(builtIn.command, config)), Effect.tap(args => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args)))));
const commandNames = ReadonlyArray.fromIterable(InternalCommand.getNames(self.command));
if (ReadonlyArray.isNonEmptyReadonlyArray(commandNames)) {
const programName = ReadonlyArray.headNonEmpty(commandNames);
const summary = InternalSpan.isEmpty(self.summary) ? InternalSpan.empty : InternalSpan.spans([InternalSpan.space, InternalSpan.text("--"), InternalSpan.space, self.summary]);
const instructions = InternalHelpDoc.sequence(InternalHelpDoc.p(InternalSpan.spans([InternalSpan.text("The wizard mode will assist you with constructing commands for"), InternalSpan.space, InternalSpan.code(`${self.name} (${self.version})`), InternalSpan.text(".")])), InternalHelpDoc.p("Please answer all prompts provided by the wizard."));
const description = InternalHelpDoc.descriptionList([[InternalSpan.text("Instructions"), instructions]]);
const header = InternalHelpDoc.h1(InternalSpan.spans([InternalSpan.code("Wizard Mode for CLI Application:"), InternalSpan.space, InternalSpan.code(self.name), InternalSpan.space, InternalSpan.code(`(${self.version})`), summary]));
const help = InternalHelpDoc.sequence(header, description);
const text = InternalHelpDoc.toAnsiText(help);
return Console.log(text).pipe(Effect.zipRight(InternalCommand.wizard(builtIn.command, programName, config)), Effect.tap(args => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args)))), Effect.catchTag("QuitException", () => {
const message = InternalHelpDoc.p(InternalSpan.error("\n\nQuitting wizard mode..."));
return Console.log(InternalHelpDoc.toAnsiText(message));
}));
}
throw new Error("[BUG]: BuiltInOptions.showWizard - received empty list of command names");
}

@@ -150,5 +159,5 @@ case "ShowVersion":

const params = pipe(ReadonlyArray.filter(args, param => param.length > 0), ReadonlyArray.join(" "));
const executeMsg = InternalSpan.weak("You may now execute your command directly with the following options and arguments:");
return InternalHelpDoc.blocks([InternalHelpDoc.p(""), InternalHelpDoc.p(InternalSpan.strong(InternalSpan.code("Wizard Mode Complete!"))), InternalHelpDoc.p(executeMsg), InternalHelpDoc.p(InternalSpan.code(` ${params}`))]);
const executeMsg = InternalSpan.text("You may now execute your command directly with the following options and arguments:");
return InternalHelpDoc.blocks([InternalHelpDoc.p(InternalSpan.strong(InternalSpan.code("Wizard Mode Complete!"))), InternalHelpDoc.p(executeMsg), InternalHelpDoc.p(InternalSpan.concat(InternalSpan.text(" "), InternalSpan.highlight(params, Color.cyan)))]);
};
//# sourceMappingURL=cliApp.js.map

@@ -98,10 +98,6 @@ import * as Context from "effect/Context";

/** @internal */
export const fromDescriptor = /*#__PURE__*/dual(2, (descriptor, handler) => makeProto(descriptor, handler));
/** @internal */
export const fromDescriptorUnit = descriptor => makeProto(descriptor, _ => Effect.unit);
/** @internal */
export const fromDescriptorHelp = descriptor => {
const self = makeProto(descriptor, _ => Effect.fail(ValidationError.helpRequested(getDescriptor(self))));
export const fromDescriptor = /*#__PURE__*/dual(args => InternalDescriptor.isCommand(args[0]), (descriptor, handler) => {
const self = makeProto(descriptor, handler ?? (_ => Effect.failSync(() => ValidationError.helpRequested(getDescriptor(self)))));
return self;
};
});
const makeDescriptor = (name, config) => {

@@ -119,12 +115,19 @@ const {

/** @internal */
export const make = (name, config, handler) => makeProto(makeDescriptor(name, config), handler);
export const make = (name, config = {}, handler) => fromDescriptor(makeDescriptor(name, config), handler);
/** @internal */
export const makeUnit = (name, config = {}) => fromDescriptorUnit(makeDescriptor(name, config));
export const getHelp = self => InternalDescriptor.getHelp(self.descriptor);
/** @internal */
export const makeHelp = (name, config = {}) => fromDescriptorHelp(makeDescriptor(name, config));
export const getNames = self => InternalDescriptor.getNames(self.descriptor);
/** @internal */
export const mapDescriptor = /*#__PURE__*/dual(2, (self, f) => makeProto(f(getDescriptor(self)), self.handler, self.tag));
export const getBashCompletions = (self, programName) => InternalDescriptor.getBashCompletions(self.descriptor, programName);
/** @internal */
export const mapBoth = /*#__PURE__*/dual(3, (self, f, g) => makeProto(f(getDescriptor(self)), _ => self.handler(g(_)), self.tag));
export const getFishCompletions = (self, programName) => InternalDescriptor.getFishCompletions(self.descriptor, programName);
/** @internal */
export const getZshCompletions = (self, programName) => InternalDescriptor.getZshCompletions(self.descriptor, programName);
/** @internal */
export const getSubcommands = self => InternalDescriptor.getSubcommands(self.descriptor);
/** @internal */
export const getUsage = self => InternalDescriptor.getUsage(self.descriptor);
const mapDescriptor = /*#__PURE__*/dual(2, (self, f) => makeProto(f(getDescriptor(self)), self.handler, self.tag));
/** @internal */
export const prompt = (name, prompt, handler) => makeProto(InternalDescriptor.map(InternalDescriptor.prompt(name, prompt), _ => _.value), handler);

@@ -150,2 +153,4 @@ /** @internal */

/** @internal */
export const wizard = /*#__PURE__*/dual(3, (self, rootCommand, config) => InternalDescriptor.wizard(self.descriptor, rootCommand, config));
/** @internal */
export const run = /*#__PURE__*/dual(2, (self, config) => {

@@ -152,0 +157,0 @@ const app = InternalCliApp.make({

@@ -0,1 +1,2 @@

import * as Color from "@effect/printer-ansi/Color";
import * as Console from "effect/Console";

@@ -11,2 +12,3 @@ import * as Effect from "effect/Effect";

import * as ReadonlyArray from "effect/ReadonlyArray";
import * as Ref from "effect/Ref";
import * as SynchronizedRef from "effect/SynchronizedRef";

@@ -130,3 +132,3 @@ import * as HelpDoc from "../HelpDoc.js";

/** @internal */
export const wizard = /*#__PURE__*/dual(2, (self, config) => wizardInternal(self, config));
export const wizard = /*#__PURE__*/dual(3, (self, rootCommand, config) => wizardInternal(self, rootCommand, config));
// =============================================================================

@@ -342,3 +344,3 @@ // Internals

{
return InternalPrompt.run(self.prompt).pipe(Effect.map(value => InternalCommandDirective.userDefined(ReadonlyArray.drop(args, 1), {
return InternalPrompt.run(self.prompt).pipe(Effect.catchTag("QuitException", e => Effect.die(e)), Effect.map(value => InternalCommandDirective.userDefined(ReadonlyArray.drop(args, 1), {
name: self.name,

@@ -481,12 +483,37 @@ value

};
const wizardInternal = (self, config) => {
const loop = self => {
const argsWizardHeader = /*#__PURE__*/InternalSpan.code("Args Wizard - ");
const optionsWizardHeader = /*#__PURE__*/InternalSpan.code("Options Wizard - ");
const wizardInternal = (self, rootCommand, config) => {
const loop = (self, commandLineRef) => {
switch (self._tag) {
case "SingleCommandWizard":
{
const optionsWizard = isStandard(self.command) ? InternalOptions.wizard(self.command.options, config) : Effect.succeed(ReadonlyArray.empty());
const argsWizard = isStandard(self.command) ? InternalArgs.wizard(self.command.args, config) : Effect.succeed(ReadonlyArray.empty());
const help = InternalHelpDoc.p(pipe(InternalSpan.text("\n"), InternalSpan.concat(InternalSpan.strong(InternalSpan.code("COMMAND:"))), InternalSpan.concat(InternalSpan.space), InternalSpan.concat(InternalSpan.code(self.command.name))));
const message = InternalHelpDoc.toAnsiText(help);
return Console.log(message).pipe(Effect.zipRight(Effect.zipWith(optionsWizard, argsWizard, (options, args) => pipe(ReadonlyArray.appendAll(options, args), ReadonlyArray.prepend(self.command.name)))));
return Effect.gen(function* (_) {
const logCurrentCommand = Ref.get(commandLineRef).pipe(Effect.flatMap(commandLine => {
const currentCommand = InternalHelpDoc.p(pipe(InternalSpan.strong(InternalSpan.highlight("COMMAND:", Color.cyan)), InternalSpan.concat(InternalSpan.space), InternalSpan.concat(InternalSpan.highlight(ReadonlyArray.join(commandLine, " "), Color.magenta))));
return Console.log(InternalHelpDoc.toAnsiText(currentCommand));
}));
if (isStandard(self.command)) {
// Log the current command line arguments
yield* _(logCurrentCommand);
const commandName = InternalSpan.highlight(self.command.name, Color.magenta);
// If the command has options, run the wizard for them
if (!InternalOptions.isEmpty(self.command.options)) {
const message = InternalHelpDoc.p(InternalSpan.concat(optionsWizardHeader, commandName));
yield* _(Console.log(InternalHelpDoc.toAnsiText(message)));
const options = yield* _(InternalOptions.wizard(self.command.options, config));
yield* _(Ref.updateAndGet(commandLineRef, ReadonlyArray.appendAll(options)));
yield* _(logCurrentCommand);
}
// If the command has args, run the wizard for them
if (!InternalArgs.isEmpty(self.command.args)) {
const message = InternalHelpDoc.p(InternalSpan.concat(argsWizardHeader, commandName));
yield* _(Console.log(InternalHelpDoc.toAnsiText(message)));
const options = yield* _(InternalArgs.wizard(self.command.args, config));
yield* _(Ref.updateAndGet(commandLineRef, ReadonlyArray.appendAll(options)));
yield* _(logCurrentCommand);
}
}
return yield* _(Ref.get(commandLineRef));
});
}

@@ -497,3 +524,3 @@ case "AlternativeCommandWizard":

title,
value
value: [title, value]
});

@@ -517,11 +544,11 @@ const choices = self.alternatives.map(alternative => {

choices
}).pipe(Effect.flatMap(nextSequence => loop(nextSequence)));
}).pipe(Effect.tap(([name]) => Ref.update(commandLineRef, ReadonlyArray.append(name))), Effect.zipLeft(Console.log()), Effect.flatMap(([, nextSequence]) => loop(nextSequence, commandLineRef)));
}
case "SubcommandWizard":
{
return Effect.zipWith(loop(self.parent), loop(self.child), (parent, child) => ReadonlyArray.appendAll(parent, child));
return loop(self.parent, commandLineRef).pipe(Effect.zipRight(loop(self.child, commandLineRef)));
}
}
};
return loop(getWizardCommandSequence(self));
return Ref.make(ReadonlyArray.of(rootCommand)).pipe(Effect.flatMap(commandLineRef => loop(getWizardCommandSequence(self), commandLineRef).pipe(Effect.zipRight(Ref.get(commandLineRef)))));
};

@@ -528,0 +555,0 @@ /**

@@ -16,15 +16,10 @@ import * as AnsiStyle from "@effect/printer-ansi/AnsiStyle";

/** @internal */
export const code = value => ({
_tag: "Code",
value
});
export const code = value => highlight(value, Color.white);
/** @internal */
export const error = value => ({
_tag: "Error",
value: typeof value === "string" ? text(value) : value
});
export const error = value => highlight(value, Color.red);
/** @internal */
export const weak = value => ({
_tag: "Weak",
value: typeof value === "string" ? text(value) : value
export const highlight = (value, color) => ({
_tag: "Highlight",
value: typeof value === "string" ? text(value) : value,
color
});

@@ -42,6 +37,7 @@ /** @internal */

/** @internal */
export const isCode = self => self._tag === "Code";
export const weak = value => ({
_tag: "Weak",
value: typeof value === "string" ? text(value) : value
});
/** @internal */
export const isError = self => self._tag === "Error";
/** @internal */
export const isSequence = self => self._tag === "Sequence";

@@ -65,3 +61,2 @@ /** @internal */

case "Text":
case "Code":
case "URI":

@@ -71,3 +66,3 @@ {

}
case "Error":
case "Highlight":
case "Weak":

@@ -97,3 +92,2 @@ case "Strong":

switch (self._tag) {
case "Code":
case "Text":

@@ -104,3 +98,3 @@ case "URI":

}
case "Error":
case "Highlight":
case "Strong":

@@ -120,22 +114,18 @@ case "Weak":

switch (self._tag) {
case "Text":
case "Highlight":
{
return Doc.text(self.value);
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.color(self.color));
}
case "Code":
case "Sequence":
{
return Doc.annotate(Doc.text(self.value), AnsiStyle.color(Color.white));
return Doc.cat(toAnsiDoc(self.left), toAnsiDoc(self.right));
}
case "Error":
case "Strong":
{
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.color(Color.red));
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.bold);
}
case "Weak":
case "Text":
{
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.dullColor(Color.black));
return Doc.text(self.value);
}
case "Strong":
{
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.bold);
}
case "URI":

@@ -145,5 +135,5 @@ {

}
case "Sequence":
case "Weak":
{
return Doc.cat(toAnsiDoc(self.left), toAnsiDoc(self.right));
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.dullColor(Color.black));
}

@@ -150,0 +140,0 @@ }

@@ -852,3 +852,2 @@ import * as Console from "effect/Console";

};
const wizardHeader = /*#__PURE__*/InternalHelpDoc.p("Option Wizard");
const wizardInternal = (self, config) => {

@@ -862,20 +861,19 @@ switch (self._tag) {

{
const help = InternalHelpDoc.sequence(wizardHeader, getHelpInternal(self));
return Console.log().pipe(Effect.zipRight(InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap(input => {
const help = getHelpInternal(self);
return InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap(input => {
// There will always be at least one name in names
const args = ReadonlyArray.make(getNames(self)[0], input);
return parseOptions(self, args, config).pipe(Effect.as(args));
}))));
}), Effect.zipLeft(Console.log()));
}
case "KeyValueMap":
{
const optionHelp = InternalHelpDoc.p("Enter `key=value` pairs separated by spaces");
const message = InternalHelpDoc.sequence(wizardHeader, optionHelp);
return Console.log().pipe(Effect.zipRight(InternalListPrompt.list({
const message = InternalHelpDoc.p("Enter `key=value` pairs separated by spaces");
return InternalListPrompt.list({
message: InternalHelpDoc.toAnsiText(message).trim(),
delimiter: " "
})), Effect.flatMap(args => {
}).pipe(Effect.flatMap(args => {
const identifier = Option.getOrElse(getIdentifierInternal(self), () => "");
return parseInternal(self, HashMap.make([identifier, args]), config).pipe(Effect.as(ReadonlyArray.prepend(args, identifier)));
}));
}), Effect.zipLeft(Console.log()));
}

@@ -893,3 +891,3 @@ case "Map":

const alternativeHelp = InternalHelpDoc.p("Select which option you would like to use");
const message = pipe(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self)), InternalHelpDoc.sequence(alternativeHelp));
const message = pipe(getHelpInternal(self), InternalHelpDoc.sequence(alternativeHelp));
const makeChoice = (title, value) => ({

@@ -900,6 +898,6 @@ title,

const choices = ReadonlyArray.compact([Option.map(getIdentifierInternal(self.left), title => makeChoice(title, self.left)), Option.map(getIdentifierInternal(self.right), title => makeChoice(title, self.right))]);
return Console.log().pipe(Effect.zipRight(InternalSelectPrompt.select({
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
choices
})), Effect.flatMap(option => wizardInternal(option, config)));
}).pipe(Effect.flatMap(option => wizardInternal(option, config)));
}

@@ -909,8 +907,8 @@ case "Variadic":

const repeatHelp = InternalHelpDoc.p("How many times should this argument should be repeated?");
const message = pipe(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self)), InternalHelpDoc.sequence(repeatHelp));
return Console.log().pipe(Effect.zipRight(InternalNumberPrompt.integer({
const message = pipe(getHelpInternal(self), InternalHelpDoc.sequence(repeatHelp));
return InternalNumberPrompt.integer({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
min: getMinSizeInternal(self),
max: getMaxSizeInternal(self)
})), Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.argumentOption, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)))))));
}).pipe(Effect.flatMap(n => Ref.make(ReadonlyArray.empty()).pipe(Effect.flatMap(ref => wizardInternal(self.argumentOption, config).pipe(Effect.flatMap(args => Ref.update(ref, ReadonlyArray.appendAll(args))), Effect.repeatN(n - 1), Effect.zipRight(Ref.get(ref)))))));
}

@@ -923,4 +921,4 @@ case "WithDefault":

const defaultHelp = InternalHelpDoc.p(`This option is optional - use the default?`);
const message = pipe(wizardHeader, InternalHelpDoc.sequence(getHelpInternal(self.options)), InternalHelpDoc.sequence(defaultHelp));
return Console.log().pipe(Effect.zipRight(InternalSelectPrompt.select({
const message = pipe(getHelpInternal(self.options), InternalHelpDoc.sequence(defaultHelp));
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),

@@ -934,3 +932,3 @@ choices: [{

}]
})), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.options, config)));
}).pipe(Effect.zipLeft(Console.log()), Effect.flatMap(useFallback => useFallback ? Effect.succeed(ReadonlyArray.empty()) : wizardInternal(self.options, config)));
}

@@ -937,0 +935,0 @@ }

@@ -327,3 +327,3 @@ import * as FileSystem from "@effect/platform/FileSystem";

inactive: "false"
}).pipe(InternalPrompt.map(bool => bool));
}).pipe(InternalPrompt.map(bool => `${bool}`));
}

@@ -330,0 +330,0 @@ case "Choice":

@@ -80,3 +80,3 @@ import * as Terminal from "@effect/platform/Terminal";

return Effect.all([Ref.make(Option.none()), Ref.make(op.initialState)]).pipe(Effect.flatMap(([prevStateRef, nextStateRef]) => {
const loop = action => Effect.all([Ref.get(prevStateRef), Ref.get(nextStateRef)]).pipe(Effect.flatMap(([prevState, nextState]) => op.render(prevState, nextState, action).pipe(Effect.flatMap(msg => Effect.orDie(terminal.display(msg))), Effect.zipRight(terminal.readInput), Effect.catchTag("QuitException", e => Effect.die(e)), Effect.flatMap(input => op.process(input, nextState)), Effect.flatMap(action => {
const loop = action => Effect.all([Ref.get(prevStateRef), Ref.get(nextStateRef)]).pipe(Effect.flatMap(([prevState, nextState]) => op.render(prevState, nextState, action).pipe(Effect.flatMap(msg => Effect.orDie(terminal.display(msg))), Effect.zipRight(terminal.readInput), Effect.flatMap(input => op.process(input, nextState)), Effect.flatMap(action => {
switch (action._tag) {

@@ -83,0 +83,0 @@ case "Beep":

{
"name": "@effect/cli",
"version": "0.0.0-snapshot-ca74efb",
"version": "0.0.0-snapshot-e8c7625",
"description": "Functional programming in TypeScript",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -5,3 +5,3 @@ /**

import type { FileSystem } from "@effect/platform/FileSystem"
import type { Terminal } from "@effect/platform/Terminal"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { Effect } from "effect/Effect"

@@ -353,4 +353,4 @@ import type { Either } from "effect/Either"

export const withDefault: {
<A>(fallback: A): (self: Args<A>) => Args<A>
<A>(self: Args<A>, fallback: A): Args<A>
<const B>(fallback: B): <A>(self: Args<A>) => Args<B | A>
<A, const B>(self: Args<A>, fallback: B): Args<A | B>
} = InternalArgs.withDefault

@@ -374,7 +374,9 @@

config: CliConfig
): <A>(self: Args<A>) => Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>
): <A>(
self: Args<A>
) => Effect<FileSystem | Terminal, ValidationError | QuitException, ReadonlyArray<string>>
<A>(
self: Args<A>,
config: CliConfig
): Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>
): Effect<FileSystem | Terminal, ValidationError | QuitException, ReadonlyArray<string>>
} = InternalArgs.wizard
/**
* @since 1.0.0
*/
import type { FileSystem } from "@effect/platform/FileSystem"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { Tag } from "effect/Context"
import type { Effect } from "effect/Effect"
import type { HashMap } from "effect/HashMap"
import type { HashSet } from "effect/HashSet"
import type { Option } from "effect/Option"

@@ -11,2 +15,3 @@ import { type Pipeable } from "effect/Pipeable"

import type { CliApp } from "./CliApp.js"
import type { CliConfig } from "./CliConfig.js"
import type * as Descriptor from "./CommandDescriptor.js"

@@ -18,2 +23,3 @@ import type { HelpDoc } from "./HelpDoc.js"

import type { Prompt } from "./Prompt.js"
import type { Usage } from "./Usage.js"
import type { ValidationError } from "./ValidationError.js"

@@ -121,5 +127,14 @@

export const fromDescriptor: {
(): <A extends { readonly name: string }>(
command: Descriptor.Command<A>
) => Command<A["name"], never, never, A>
<A extends { readonly name: string }, R, E>(
handler: (_: A) => Effect<R, E, void>
): (command: Descriptor.Command<A>) => Command<A["name"], R, E, A>
<A extends { readonly name: string }>(
descriptor: Descriptor.Command<A>
): Command<A["name"], never, never, A>
<A extends { readonly name: string }, R, E>(

@@ -133,56 +148,69 @@ descriptor: Descriptor.Command<A>,

* @since 1.0.0
* @category constructors
* @category accessors
*/
export const fromDescriptorHelp: <A extends { readonly name: string }>(
descriptor: Descriptor.Command<A>
) => Command<A["name"], never, ValidationError, A> = Internal.fromDescriptorHelp
export const getHelp: <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => HelpDoc =
Internal.getHelp
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export const fromDescriptorUnit: <A extends { readonly name: string }>(
descriptor: Descriptor.Command<A>
) => Command<A["name"], never, never, A> = Internal.fromDescriptorUnit
export const getNames: <Name extends string, R, E, A>(
self: Command<Name, R, E, A>
) => HashSet<string> = Internal.getNames
/**
* @since 1.0.0
* @category constructors
* @category accessors
*/
export const make: <Name extends string, const Config extends Command.ConfigBase, R, E>(
name: Name,
config: Config,
handler: (_: Types.Simplify<Command.ParseConfig<Config>>) => Effect<R, E, void>
) => Command<
Name,
R,
E,
Types.Simplify<Command.ParseConfig<Config>>
> = Internal.make
export const getBashCompletions: <Name extends string, R, E, A>(
self: Command<Name, R, E, A>,
programName: string
) => Effect<never, never, ReadonlyArray<string>> = Internal.getBashCompletions
/**
* @since 1.0.0
* @category accessors
*/
export const getFishCompletions: <Name extends string, R, E, A>(
self: Command<Name, R, E, A>,
programName: string
) => Effect<never, never, ReadonlyArray<string>> = Internal.getFishCompletions
/**
* @since 1.0.0
* @category accessors
*/
export const getZshCompletions: <Name extends string, R, E, A>(
self: Command<Name, R, E, A>,
programName: string
) => Effect<never, never, ReadonlyArray<string>> = Internal.getZshCompletions
/**
* @since 1.0.0
* @category accessors
*/
export const getSubcommands: <Name extends string, R, E, A>(
self: Command<Name, R, E, A>
) => HashMap<string, Descriptor.Command<unknown>> = Internal.getSubcommands
/**
* @since 1.0.0
* @category accessors
*/
export const getUsage: <Name extends string, R, E, A>(self: Command<Name, R, E, A>) => Usage =
Internal.getUsage
/**
* @since 1.0.0
* @category constructors
*/
export const makeHelp: {
<Name extends string>(name: Name): Command<Name, never, ValidationError, {}>
<Name extends string, const Config extends Command.ConfigBase>(
name: Name,
config: Config
): Command<
export const make: {
<Name extends string>(name: Name): Command<
Name,
never,
ValidationError,
Types.Simplify<
Types.Simplify<{ readonly [Key in keyof Config]: Command.ParseConfigValue<Config[Key]> }>
>
never,
{}
>
} = Internal.makeHelp
/**
* @since 1.0.0
* @category constructors
*/
export const makeUnit: {
<Name extends string>(name: Name): Command<Name, {}, never, never>
<Name extends string, const Config extends Command.ConfigBase>(

@@ -195,21 +223,16 @@ name: Name,

never,
Types.Simplify<
Types.Simplify<{ readonly [Key in keyof Config]: Command.ParseConfigValue<Config[Key]> }>
>
Types.Simplify<Command.ParseConfig<Config>>
>
} = Internal.makeUnit
/**
* @since 1.0.0
* @category combinators
*/
export const mapDescriptor: {
<A>(
f: (_: Descriptor.Command<A>) => Descriptor.Command<A>
): <Name extends string, R, E>(self: Command<Name, R, E, A>) => Command<Name, R, E, A>
<Name extends string, R, E, A>(
self: Command<Name, R, E, A>,
f: (_: Descriptor.Command<A>) => Descriptor.Command<A>
): Command<Name, R, E, A>
} = Internal.mapDescriptor
<Name extends string, const Config extends Command.ConfigBase, R, E>(
name: Name,
config: Config,
handler: (_: Types.Simplify<Command.ParseConfig<Config>>) => Effect<R, E, void>
): Command<
Name,
R,
E,
Types.Simplify<Command.ParseConfig<Config>>
>
} = Internal.make

@@ -288,2 +311,20 @@ /**

* @since 1.0.0
* @category accessors
*/
export const wizard: {
(
rootCommand: string,
config: CliConfig
): <Name extends string, R, E, A>(
self: Command<Name, R, E, A>
) => Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>
<Name extends string, R, E, A>(
self: Command<Name, R, E, A>,
rootCommand: string,
config: CliConfig
): Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>
} = Internal.wizard
/**
* @since 1.0.0
* @category conversions

@@ -290,0 +331,0 @@ */

@@ -5,3 +5,3 @@ /**

import type { FileSystem } from "@effect/platform/FileSystem"
import type { Terminal } from "@effect/platform/Terminal"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { Effect } from "effect/Effect"

@@ -178,20 +178,2 @@ import type { Either } from "effect/Either"

*/
export const orElse: {
<B>(that: Command<B>): <A>(self: Command<A>) => Command<A | B>
<A, B>(self: Command<A>, that: Command<B>): Command<A | B>
} = Internal.orElse
/**
* @since 1.0.0
* @category combinators
*/
export const orElseEither: {
<B>(that: Command<B>): <A>(self: Command<A>) => Command<Either<A, B>>
<A, B>(self: Command<A>, that: Command<B>): Command<Either<A, B>>
} = Internal.orElseEither
/**
* @since 1.0.0
* @category combinators
*/
export const parse: {

@@ -246,3 +228,3 @@ (

<
Subcommands extends readonly [
const Subcommands extends readonly [
readonly [id: unknown, command: Command<any>],

@@ -262,3 +244,3 @@ ...Array<readonly [id: unknown, command: Command<any>]>

A,
Subcommands extends readonly [
const Subcommands extends readonly [
readonly [id: unknown, command: Command<any>],

@@ -283,10 +265,12 @@ ...Array<readonly [id: unknown, command: Command<any>]>

(
rootCommand: string,
config: CliConfig
): <A>(
self: Command<A>
) => Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>
) => Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>
<A>(
self: Command<A>,
rootCommand: string,
config: CliConfig
): Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>
): Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>
} = Internal.wizard
/**
* @since 1.0.0
*/
import type { Color } from "@effect/printer-ansi/Color"
import * as InternalSpan from "../internal/helpDoc/span.js"

@@ -10,3 +11,3 @@

*/
export type Span = Text | Code | Error | Weak | Strong | URI | Sequence
export type Span = Highlight | Sequence | Strong | Text | URI | Weak

@@ -17,5 +18,6 @@ /**

*/
export interface Text {
readonly _tag: "Text"
readonly value: string
export interface Highlight {
readonly _tag: "Highlight"
readonly value: Span
readonly color: Color
}

@@ -27,5 +29,6 @@

*/
export interface Code {
readonly _tag: "Code"
readonly value: string
export interface Sequence {
readonly _tag: "Sequence"
readonly left: Span
readonly right: Span
}

@@ -37,4 +40,4 @@

*/
export interface Error {
readonly _tag: "Error"
export interface Strong {
readonly _tag: "Strong"
readonly value: Span

@@ -47,5 +50,5 @@ }

*/
export interface Weak {
readonly _tag: "Weak"
readonly value: Span
export interface Text {
readonly _tag: "Text"
readonly value: string
}

@@ -57,11 +60,2 @@

*/
export interface Strong {
readonly _tag: "Strong"
readonly value: Span
}
/**
* @since 1.0.0
* @category models
*/
export interface URI {

@@ -76,6 +70,5 @@ readonly _tag: "URI"

*/
export interface Sequence {
readonly _tag: "Sequence"
readonly left: Span
readonly right: Span
export interface Weak {
readonly _tag: "Weak"
readonly value: Span
}

@@ -87,8 +80,2 @@

*/
export const isError: (self: Span) => self is Error = InternalSpan.isError
/**
* @since 1.0.0
* @category refinements
*/
export const isSequence: (self: Span) => self is Sequence = InternalSpan.isSequence

@@ -142,3 +129,3 @@

*/
export const code: (value: string) => Span = InternalSpan.code
export const code: (value: string | Span) => Span = InternalSpan.code

@@ -145,0 +132,0 @@ /**

@@ -332,4 +332,4 @@ import type * as FileSystem from "@effect/platform/FileSystem"

export const withDefault = dual<
<A>(fallback: A) => (self: Args.Args<A>) => Args.Args<A>,
<A>(self: Args.Args<A>, fallback: A) => Args.Args<A>
<const B>(fallback: B) => <A>(self: Args.Args<A>) => Args.Args<A | B>,
<A, const B>(self: Args.Args<A>, fallback: B) => Args.Args<A | B>
>(2, (self, fallback) => makeWithDefault(self, fallback))

@@ -347,3 +347,3 @@

FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>

@@ -353,3 +353,3 @@ >,

FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>

@@ -577,6 +577,6 @@ >

const makeWithDefault = <A>(
const makeWithDefault = <A, const B>(
self: Args.Args<A>,
fallback: A
): Args.Args<A> => {
fallback: B
): Args.Args<A | B> => {
const op = Object.create(proto)

@@ -741,7 +741,5 @@ op._tag = "WithDefault"

const wizardHeader = InternalHelpDoc.p("ARG WIZARD")
const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.Effect<
FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>

@@ -754,10 +752,9 @@ > => {

case "Single": {
const help = InternalHelpDoc.sequence(wizardHeader, getHelpInternal(self))
return Console.log().pipe(
Effect.zipRight(
InternalPrimitive.wizard(self.primitiveType, help).pipe(Effect.flatMap((input) => {
const args = ReadonlyArray.of(input as string)
return validateInternal(self, args, config).pipe(Effect.as(args))
}))
)
const help = getHelpInternal(self)
return InternalPrimitive.wizard(self.primitiveType, help).pipe(
Effect.zipLeft(Console.log()),
Effect.flatMap((input) => {
const args = ReadonlyArray.of(input as string)
return validateInternal(self, args, config).pipe(Effect.as(args))
})
)

@@ -782,12 +779,11 @@ }

const message = pipe(
wizardHeader,
InternalHelpDoc.sequence(getHelpInternal(self)),
getHelpInternal(self),
InternalHelpDoc.sequence(repeatHelp)
)
return Console.log().pipe(
Effect.zipRight(InternalNumberPrompt.integer({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
min: getMinSizeInternal(self),
max: getMaxSizeInternal(self)
})),
return InternalNumberPrompt.integer({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
min: getMinSizeInternal(self),
max: getMaxSizeInternal(self)
}).pipe(
Effect.zipLeft(Console.log()),
Effect.flatMap((n) =>

@@ -810,16 +806,13 @@ Ref.make(ReadonlyArray.empty<string>()).pipe(

const message = pipe(
wizardHeader,
InternalHelpDoc.sequence(getHelpInternal(self.args as Instruction)),
getHelpInternal(self.args as Instruction),
InternalHelpDoc.sequence(defaultHelp)
)
return Console.log().pipe(
Effect.zipRight(
InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
choices: [
{ title: `Default ['${JSON.stringify(self.fallback)}']`, value: true },
{ title: "Custom", value: false }
]
})
),
return InternalSelectPrompt.select({
message: InternalHelpDoc.toAnsiText(message).trimEnd(),
choices: [
{ title: `Default ['${JSON.stringify(self.fallback)}']`, value: true },
{ title: "Custom", value: false }
]
}).pipe(
Effect.zipLeft(Console.log()),
Effect.flatMap((useFallback) =>

@@ -826,0 +819,0 @@ useFallback

import type * as Terminal from "@effect/platform/Terminal"
import * as Color from "@effect/printer-ansi/Color"
import * as Console from "effect/Console"

@@ -188,39 +189,50 @@ import * as Context from "effect/Context"

case "ShowWizard": {
const summary = InternalSpan.isEmpty(self.summary)
? InternalSpan.empty
: InternalSpan.spans([
InternalSpan.space,
InternalSpan.text("--"),
InternalSpan.space,
self.summary
])
const instructions = InternalHelpDoc.sequence(
InternalHelpDoc.p(InternalSpan.spans([
InternalSpan.text("The wizard mode will assist you with constructing commands for"),
InternalSpan.space,
InternalSpan.code(`${self.name} (${self.version})`),
InternalSpan.text(".")
])),
InternalHelpDoc.p("Please answer all prompts provided by the wizard.")
const commandNames = ReadonlyArray.fromIterable(InternalCommand.getNames(self.command))
if (ReadonlyArray.isNonEmptyReadonlyArray(commandNames)) {
const programName = ReadonlyArray.headNonEmpty(commandNames)
const summary = InternalSpan.isEmpty(self.summary)
? InternalSpan.empty
: InternalSpan.spans([
InternalSpan.space,
InternalSpan.text("--"),
InternalSpan.space,
self.summary
])
const instructions = InternalHelpDoc.sequence(
InternalHelpDoc.p(InternalSpan.spans([
InternalSpan.text("The wizard mode will assist you with constructing commands for"),
InternalSpan.space,
InternalSpan.code(`${self.name} (${self.version})`),
InternalSpan.text(".")
])),
InternalHelpDoc.p("Please answer all prompts provided by the wizard.")
)
const description = InternalHelpDoc.descriptionList([[
InternalSpan.text("Instructions"),
instructions
]])
const header = InternalHelpDoc.h1(
InternalSpan.spans([
InternalSpan.code("Wizard Mode for CLI Application:"),
InternalSpan.space,
InternalSpan.code(self.name),
InternalSpan.space,
InternalSpan.code(`(${self.version})`),
summary
])
)
const help = InternalHelpDoc.sequence(header, description)
const text = InternalHelpDoc.toAnsiText(help)
return Console.log(text).pipe(
Effect.zipRight(InternalCommand.wizard(builtIn.command, programName, config)),
Effect.tap((args) => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args)))),
Effect.catchTag("QuitException", () => {
const message = InternalHelpDoc.p(InternalSpan.error("\n\nQuitting wizard mode..."))
return Console.log(InternalHelpDoc.toAnsiText(message))
})
)
}
throw new Error(
"[BUG]: BuiltInOptions.showWizard - received empty list of command names"
)
const description = InternalHelpDoc.descriptionList([[
InternalSpan.text("Instructions"),
instructions
]])
const header = InternalHelpDoc.h1(
InternalSpan.spans([
InternalSpan.code("Wizard Mode for CLI Application:"),
InternalSpan.space,
InternalSpan.code(self.name),
InternalSpan.space,
InternalSpan.code(`(${self.version})`),
summary
])
)
const help = InternalHelpDoc.sequence(header, description)
const text = InternalHelpDoc.toAnsiText(help).trimEnd()
return Console.log(text).pipe(
Effect.zipRight(InternalCommand.wizard(builtIn.command, config)),
Effect.tap((args) => Console.log(InternalHelpDoc.toAnsiText(renderWizardArgs(args))))
)
}

@@ -272,11 +284,13 @@ case "ShowVersion": {

)
const executeMsg = InternalSpan.weak(
const executeMsg = InternalSpan.text(
"You may now execute your command directly with the following options and arguments:"
)
return InternalHelpDoc.blocks([
InternalHelpDoc.p(""),
InternalHelpDoc.p(InternalSpan.strong(InternalSpan.code("Wizard Mode Complete!"))),
InternalHelpDoc.p(executeMsg),
InternalHelpDoc.p(InternalSpan.code(` ${params}`))
InternalHelpDoc.p(InternalSpan.concat(
InternalSpan.text(" "),
InternalSpan.highlight(params, Color.cyan)
))
])
}

@@ -0,1 +1,3 @@

import type { FileSystem } from "@effect/platform/FileSystem"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import * as Context from "effect/Context"

@@ -6,2 +8,4 @@ import * as Effect from "effect/Effect"

import { globalValue } from "effect/GlobalValue"
import type { HashMap } from "effect/HashMap"
import type { HashSet } from "effect/HashSet"
import type * as Option from "effect/Option"

@@ -13,2 +17,3 @@ import { pipeArguments } from "effect/Pipeable"

import type * as CliApp from "../CliApp.js"
import type { CliConfig } from "../CliConfig.js"
import type * as Command from "../Command.js"

@@ -20,2 +25,3 @@ import type * as Descriptor from "../CommandDescriptor.js"

import type * as Prompt from "../Prompt.js"
import type { Usage } from "../Usage.js"
import * as ValidationError from "../ValidationError.js"

@@ -147,27 +153,31 @@ import * as InternalArgs from "./args.js"

export const fromDescriptor = dual<
<A extends { readonly name: string }, R, E>(
handler: (_: A) => Effect.Effect<R, E, void>
) => (command: Descriptor.Command<A>) => Command.Command<A["name"], R, E, A>,
<A extends { readonly name: string }, R, E>(
descriptor: Descriptor.Command<A>,
handler: (_: A) => Effect.Effect<R, E, void>
) => Command.Command<A["name"], R, E, A>
>(2, (descriptor, handler) => makeProto(descriptor, handler))
{
(): <A extends { readonly name: string }>(
command: Descriptor.Command<A>
) => Command.Command<A["name"], never, never, A>
<A extends { readonly name: string }, R, E>(
handler: (_: A) => Effect.Effect<R, E, void>
): (command: Descriptor.Command<A>) => Command.Command<A["name"], R, E, A>
},
{
<A extends { readonly name: string }>(
descriptor: Descriptor.Command<A>
): Command.Command<A["name"], never, never, A>
<A extends { readonly name: string }, R, E>(
descriptor: Descriptor.Command<A>,
handler: (_: A) => Effect.Effect<R, E, void>
): Command.Command<A["name"], R, E, A>
}
>(
(args) => InternalDescriptor.isCommand(args[0]),
(descriptor: Descriptor.Command<any>, handler?: (_: any) => Effect.Effect<any, any, any>) => {
const self: Command.Command<any, any, any, any> = makeProto(
descriptor,
handler ??
((_) => Effect.failSync(() => ValidationError.helpRequested(getDescriptor(self))))
)
return self as any
}
)
/** @internal */
export const fromDescriptorUnit = <A extends { readonly name: string }>(
descriptor: Descriptor.Command<A>
): Command.Command<A["name"], never, never, A> => makeProto(descriptor, (_) => Effect.unit)
/** @internal */
export const fromDescriptorHelp = <A extends { readonly name: string }>(
descriptor: Descriptor.Command<A>
): Command.Command<A["name"], never, ValidationError.ValidationError, A> => {
const self: Command.Command<A["name"], never, ValidationError.ValidationError, A> = makeProto(
descriptor,
(_) => Effect.fail(ValidationError.helpRequested(getDescriptor(self)))
)
return self
}
const makeDescriptor = <const Config extends Command.Command.ConfigBase>(

@@ -185,18 +195,10 @@ name: string,

/** @internal */
export const make = <Name extends string, const Config extends Command.Command.ConfigBase, R, E>(
name: Name,
config: Config,
handler: (_: Types.Simplify<Command.Command.ParseConfig<Config>>) => Effect.Effect<R, E, void>
): Command.Command<
Name,
R,
E,
Types.Simplify<Command.Command.ParseConfig<Config>>
> => makeProto(makeDescriptor(name, config), handler)
export const make: {
<Name extends string>(name: Name): Command.Command<
Name,
never,
never,
{}
>
/** @internal */
export const makeUnit: {
<Name extends string>(
name: Name
): Command.Command<Name, {}, never, never>
<Name extends string, const Config extends Command.Command.ConfigBase>(

@@ -211,22 +213,62 @@ name: Name,

>
} = (name: string, config = {}) => fromDescriptorUnit(makeDescriptor(name, config) as any) as any
/** @internal */
export const makeHelp: {
<Name extends string>(
name: Name
): Command.Command<Name, never, ValidationError.ValidationError, {}>
<Name extends string, const Config extends Command.Command.ConfigBase>(
<Name extends string, const Config extends Command.Command.ConfigBase, R, E>(
name: Name,
config: Config
config: Config,
handler: (_: Types.Simplify<Command.Command.ParseConfig<Config>>) => Effect.Effect<R, E, void>
): Command.Command<
Name,
never,
ValidationError.ValidationError,
R,
E,
Types.Simplify<Command.Command.ParseConfig<Config>>
>
} = (name: string, config = {}) => fromDescriptorHelp(makeDescriptor(name, config) as any) as any
} = (
name: string,
config: Command.Command.ConfigBase = {},
handler?: (_: any) => Effect.Effect<any, any, any>
) => fromDescriptor(makeDescriptor(name, config) as any, handler as any) as any
/** @internal */
export const mapDescriptor = dual<
export const getHelp = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>
): HelpDoc => InternalDescriptor.getHelp(self.descriptor)
/** @internal */
export const getNames = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>
): HashSet<string> => InternalDescriptor.getNames(self.descriptor)
/** @internal */
export const getBashCompletions = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>,
programName: string
): Effect.Effect<never, never, ReadonlyArray<string>> =>
InternalDescriptor.getBashCompletions(self.descriptor, programName)
/** @internal */
export const getFishCompletions = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>,
programName: string
): Effect.Effect<never, never, ReadonlyArray<string>> =>
InternalDescriptor.getFishCompletions(self.descriptor, programName)
/** @internal */
export const getZshCompletions = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>,
programName: string
): Effect.Effect<never, never, ReadonlyArray<string>> =>
InternalDescriptor.getZshCompletions(self.descriptor, programName)
/** @internal */
export const getSubcommands = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>
): HashMap<string, Descriptor.Command<unknown>> =>
InternalDescriptor.getSubcommands(self.descriptor)
/** @internal */
export const getUsage = <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>
): Usage => InternalDescriptor.getUsage(self.descriptor)
const mapDescriptor = dual<
<A>(f: (_: Descriptor.Command<A>) => Descriptor.Command<A>) => <Name extends string, R, E>(

@@ -242,17 +284,2 @@ self: Command.Command<Name, R, E, A>

/** @internal */
export const mapBoth = dual<
<A, B>(
f: (_: Descriptor.Command<A>) => Descriptor.Command<B>,
g: (_: B) => A
) => <Name extends string, R, E>(
self: Command.Command<Name, R, E, A>
) => Command.Command<Name, R, E, B>,
<Name extends string, R, E, A, B>(
self: Command.Command<Name, R, E, A>,
f: (_: Descriptor.Command<A>) => Descriptor.Command<B>,
g: (_: B) => A
) => Command.Command<Name, R, E, B>
>(3, (self, f, g) => makeProto(f(getDescriptor(self)), (_) => self.handler(g(_)), self.tag))
/** @internal */
export const prompt = <Name extends string, A, R, E>(

@@ -368,2 +395,25 @@ name: Name,

/** @internal */
export const wizard = dual<
(
rootCommand: string,
config: CliConfig
) => <Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>
) => Effect.Effect<
FileSystem | Terminal,
QuitException | ValidationError.ValidationError,
ReadonlyArray<string>
>,
<Name extends string, R, E, A>(
self: Command.Command<Name, R, E, A>,
rootCommand: string,
config: CliConfig
) => Effect.Effect<
FileSystem | Terminal,
QuitException | ValidationError.ValidationError,
ReadonlyArray<string>
>
>(3, (self, rootCommand, config) => InternalDescriptor.wizard(self.descriptor, rootCommand, config))
/** @internal */
export const run = dual<

@@ -370,0 +420,0 @@ (config: {

import type * as FileSystem from "@effect/platform/FileSystem"
import type * as Terminal from "@effect/platform/Terminal"
import * as Color from "@effect/printer-ansi/Color"
import * as Console from "effect/Console"

@@ -13,2 +14,3 @@ import * as Effect from "effect/Effect"

import * as ReadonlyArray from "effect/ReadonlyArray"
import * as Ref from "effect/Ref"
import * as SynchronizedRef from "effect/SynchronizedRef"

@@ -296,3 +298,3 @@ import type * as Args from "../Args.js"

<
Subcommands extends ReadonlyArray.NonEmptyReadonlyArray<
const Subcommands extends ReadonlyArray.NonEmptyReadonlyArray<
readonly [id: unknown, command: Descriptor.Command<any>]

@@ -312,3 +314,3 @@ >

A,
Subcommands extends ReadonlyArray.NonEmptyReadonlyArray<
const Subcommands extends ReadonlyArray.NonEmptyReadonlyArray<
readonly [id: unknown, command: Descriptor.Command<any>]

@@ -346,13 +348,20 @@ >

export const wizard = dual<
(config: CliConfig.CliConfig) => <A>(self: Descriptor.Command<A>) => Effect.Effect<
(
rootCommand: string,
config: CliConfig.CliConfig
) => <A>(self: Descriptor.Command<A>) => Effect.Effect<
FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>
>,
<A>(self: Descriptor.Command<A>, config: CliConfig.CliConfig) => Effect.Effect<
<A>(
self: Descriptor.Command<A>,
rootCommand: string,
config: CliConfig.CliConfig
) => Effect.Effect<
FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>
>
>(2, (self, config) => wizardInternal(self as Instruction, config))
>(3, (self, rootCommand, config) => wizardInternal(self as Instruction, rootCommand, config))

@@ -679,2 +688,3 @@ // =============================================================================

return InternalPrompt.run(self.prompt).pipe(
Effect.catchTag("QuitException", (e) => Effect.die(e)),
Effect.map((value) =>

@@ -875,13 +885,20 @@ InternalCommandDirective.userDefined(ReadonlyArray.drop(args, 1), {

const argsWizardHeader = InternalSpan.code("Args Wizard - ")
const optionsWizardHeader = InternalSpan.code("Options Wizard - ")
const wizardInternal = (
self: Instruction,
rootCommand: string,
config: CliConfig.CliConfig
): Effect.Effect<
FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>
> => {
const loop = (self: WizardCommandSequence): Effect.Effect<
const loop = (
self: WizardCommandSequence,
commandLineRef: Ref.Ref<ReadonlyArray<string>>
): Effect.Effect<
FileSystem.FileSystem | Terminal.Terminal,
ValidationError.ValidationError,
Terminal.QuitException | ValidationError.ValidationError,
ReadonlyArray<string>

@@ -891,25 +908,47 @@ > => {

case "SingleCommandWizard": {
const optionsWizard = isStandard(self.command)
? InternalOptions.wizard(self.command.options, config)
: Effect.succeed(ReadonlyArray.empty())
const argsWizard = isStandard(self.command)
? InternalArgs.wizard(self.command.args, config)
: Effect.succeed(ReadonlyArray.empty())
const help = InternalHelpDoc.p(pipe(
InternalSpan.text("\n"),
InternalSpan.concat(InternalSpan.strong(InternalSpan.code("COMMAND:"))),
InternalSpan.concat(InternalSpan.space),
InternalSpan.concat(InternalSpan.code(self.command.name))
))
const message = InternalHelpDoc.toAnsiText(help)
return Console.log(message).pipe(
Effect.zipRight(Effect.zipWith(optionsWizard, argsWizard, (options, args) =>
pipe(
ReadonlyArray.appendAll(options, args),
ReadonlyArray.prepend(self.command.name)
)))
)
return Effect.gen(function*(_) {
const logCurrentCommand = Ref.get(commandLineRef).pipe(Effect.flatMap((commandLine) => {
const currentCommand = InternalHelpDoc.p(pipe(
InternalSpan.strong(InternalSpan.highlight("COMMAND:", Color.cyan)),
InternalSpan.concat(InternalSpan.space),
InternalSpan.concat(InternalSpan.highlight(
ReadonlyArray.join(commandLine, " "),
Color.magenta
))
))
return Console.log(InternalHelpDoc.toAnsiText(currentCommand))
}))
if (isStandard(self.command)) {
// Log the current command line arguments
yield* _(logCurrentCommand)
const commandName = InternalSpan.highlight(self.command.name, Color.magenta)
// If the command has options, run the wizard for them
if (!InternalOptions.isEmpty(self.command.options as InternalOptions.Instruction)) {
const message = InternalHelpDoc.p(
InternalSpan.concat(optionsWizardHeader, commandName)
)
yield* _(Console.log(InternalHelpDoc.toAnsiText(message)))
const options = yield* _(InternalOptions.wizard(self.command.options, config))
yield* _(Ref.updateAndGet(commandLineRef, ReadonlyArray.appendAll(options)))
yield* _(logCurrentCommand)
}
// If the command has args, run the wizard for them
if (!InternalArgs.isEmpty(self.command.args as InternalArgs.Instruction)) {
const message = InternalHelpDoc.p(
InternalSpan.concat(argsWizardHeader, commandName)
)
yield* _(Console.log(InternalHelpDoc.toAnsiText(message)))
const options = yield* _(InternalArgs.wizard(self.command.args, config))
yield* _(Ref.updateAndGet(commandLineRef, ReadonlyArray.appendAll(options)))
yield* _(logCurrentCommand)
}
}
return yield* _(Ref.get(commandLineRef))
})
}
case "AlternativeCommandWizard": {
const makeChoice = (title: string, value: WizardCommandSequence) => ({ title, value })
const makeChoice = (title: string, value: WizardCommandSequence) => ({
title,
value: [title, value] as const
})
const choices = self.alternatives.map((alternative) => {

@@ -928,10 +967,10 @@ switch (alternative._tag) {

return InternalSelectPrompt.select({ message, choices }).pipe(
Effect.flatMap((nextSequence) => loop(nextSequence))
Effect.tap(([name]) => Ref.update(commandLineRef, ReadonlyArray.append(name))),
Effect.zipLeft(Console.log()),
Effect.flatMap(([, nextSequence]) => loop(nextSequence, commandLineRef))
)
}
case "SubcommandWizard": {
return Effect.zipWith(
loop(self.parent),
loop(self.child),
(parent, child) => ReadonlyArray.appendAll(parent, child)
return loop(self.parent, commandLineRef).pipe(
Effect.zipRight(loop(self.child, commandLineRef))
)

@@ -941,3 +980,9 @@ }

}
return loop(getWizardCommandSequence(self))
return Ref.make<ReadonlyArray<string>>(ReadonlyArray.of(rootCommand)).pipe(
Effect.flatMap((commandLineRef) =>
loop(getWizardCommandSequence(self), commandLineRef).pipe(
Effect.zipRight(Ref.get(commandLineRef))
)
)
)
}

@@ -944,0 +989,0 @@

@@ -22,17 +22,12 @@ import type * as AnsiDoc from "@effect/printer-ansi/AnsiDoc"

/** @internal */
export const code = (value: string): Span.Span => ({
_tag: "Code",
value
})
export const code = (value: Span.Span | string): Span.Span => highlight(value, Color.white)
/** @internal */
export const error = (value: Span.Span | string): Span.Span => ({
_tag: "Error",
value: typeof value === "string" ? text(value) : value
})
export const error = (value: Span.Span | string): Span.Span => highlight(value, Color.red)
/** @internal */
export const weak = (value: Span.Span | string): Span.Span => ({
_tag: "Weak",
value: typeof value === "string" ? text(value) : value
export const highlight = (value: Span.Span | string, color: Color.Color): Span.Span => ({
_tag: "Highlight",
value: typeof value === "string" ? text(value) : value,
color
})

@@ -53,8 +48,8 @@

/** @internal */
export const isCode = (self: Span.Span): self is Span.Code => self._tag === "Code"
export const weak = (value: Span.Span | string): Span.Span => ({
_tag: "Weak",
value: typeof value === "string" ? text(value) : value
})
/** @internal */
export const isError = (self: Span.Span): self is Span.Error => self._tag === "Error"
/** @internal */
export const isSequence = (self: Span.Span): self is Span.Sequence => self._tag === "Sequence"

@@ -87,7 +82,6 @@

case "Text":
case "Code":
case "URI": {
return self.value
}
case "Error":
case "Highlight":
case "Weak":

@@ -118,3 +112,2 @@ case "Strong": {

switch (self._tag) {
case "Code":
case "Text":

@@ -124,3 +117,3 @@ case "URI": {

}
case "Error":
case "Highlight":
case "Strong":

@@ -139,24 +132,21 @@ case "Weak": {

switch (self._tag) {
case "Text": {
return Doc.text(self.value)
case "Highlight": {
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.color(self.color))
}
case "Code": {
return Doc.annotate(Doc.text(self.value), AnsiStyle.color(Color.white))
case "Sequence": {
return Doc.cat(toAnsiDoc(self.left), toAnsiDoc(self.right))
}
case "Error": {
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.color(Color.red))
}
case "Weak": {
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.dullColor(Color.black))
}
case "Strong": {
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.bold)
}
case "Text": {
return Doc.text(self.value)
}
case "URI": {
return Doc.annotate(Doc.text(self.value), AnsiStyle.underlined)
}
case "Sequence": {
return Doc.cat(toAnsiDoc(self.left), toAnsiDoc(self.right))
case "Weak": {
return Doc.annotate(toAnsiDoc(self.value), AnsiStyle.dullColor(Color.black))
}
}
}

@@ -513,3 +513,3 @@ import * as FileSystem from "@effect/platform/FileSystem"

inactive: "false"
}).pipe(InternalPrompt.map((bool) => bool))
}).pipe(InternalPrompt.map((bool) => `${bool}`))
}

@@ -558,3 +558,5 @@ case "Choice": {

const message = InternalHelpDoc.sequence(help, primitiveHelp)
return InternalTextPrompt.text({ message: InternalHelpDoc.toAnsiText(message).trimEnd() })
return InternalTextPrompt.text({
message: InternalHelpDoc.toAnsiText(message).trimEnd()
})
}

@@ -561,0 +563,0 @@ }

@@ -27,3 +27,3 @@ import * as Terminal from "@effect/platform/Terminal"

},
commit(): Effect.Effect<Terminal.Terminal, never, unknown> {
commit(): Effect.Effect<Terminal.Terminal, Terminal.QuitException, unknown> {
return run(this as Prompt.Prompt<unknown>)

@@ -168,3 +168,3 @@ },

self: Prompt.Prompt<Output>
): Effect.Effect<Terminal.Terminal, never, Output> =>
): Effect.Effect<Terminal.Terminal, Terminal.QuitException, Output> =>
Effect.flatMap(Terminal.Terminal, (terminal) => {

@@ -181,3 +181,3 @@ const op = self as Primitive

action: Exclude<PromptAction.PromptAction<unknown, unknown>, { _tag: "Submit" }>
): Effect.Effect<never, never, any> =>
): Effect.Effect<never, Terminal.QuitException, any> =>
Effect.all([Ref.get(prevStateRef), Ref.get(nextStateRef)]).pipe(

@@ -188,3 +188,2 @@ Effect.flatMap(([prevState, nextState]) =>

Effect.zipRight(terminal.readInput),
Effect.catchTag("QuitException", (e) => Effect.die(e)),
Effect.flatMap((input) => op.process(input, nextState)),

@@ -191,0 +190,0 @@ Effect.flatMap((action) => {

@@ -5,3 +5,3 @@ /**

import type { FileSystem } from "@effect/platform/FileSystem"
import type { Terminal } from "@effect/platform/Terminal"
import type { QuitException, Terminal } from "@effect/platform/Terminal"
import type { Effect } from "effect/Effect"

@@ -449,4 +449,4 @@ import type { Either } from "effect/Either"

export const withDefault: {
<A>(fallback: A): (self: Options<A>) => Options<A>
<A>(self: Options<A>, fallback: A): Options<A>
<const B>(fallback: B): <A>(self: Options<A>) => Options<B | A>
<A, const B>(self: Options<A>, fallback: B): Options<A | B>
} = InternalOptions.withDefault

@@ -479,7 +479,9 @@

config: CliConfig
): <A>(self: Options<A>) => Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>
): <A>(
self: Options<A>
) => Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>
<A>(
self: Options<A>,
config: CliConfig
): Effect<FileSystem | Terminal, ValidationError, ReadonlyArray<string>>
): Effect<FileSystem | Terminal, QuitException | ValidationError, ReadonlyArray<string>>
} = InternalOptions.wizard
/**
* @since 1.0.0
*/
import type { Terminal, UserInput } from "@effect/platform/Terminal"
import type { QuitException, Terminal, UserInput } from "@effect/platform/Terminal"
import type { Effect } from "effect/Effect"

@@ -35,3 +35,3 @@ import type { Option } from "effect/Option"

export interface Prompt<Output>
extends Prompt.Variance<Output>, Pipeable, Effect<Terminal, never, Output>
extends Prompt.Variance<Output>, Pipeable, Effect<Terminal, QuitException, Output>
{}

@@ -459,3 +459,3 @@

*/
export const run: <Output>(self: Prompt<Output>) => Effect<Terminal, never, Output> =
export const run: <Output>(self: Prompt<Output>) => Effect<Terminal, QuitException, Output> =
InternalPrompt.run

@@ -462,0 +462,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc