From 12538cddad6e13408e60306a58ad4070c9f0c217 Mon Sep 17 00:00:00 2001 From: "David P. Caldwell" Date: Sun, 26 Jun 2022 09:31:34 -0400 Subject: [PATCH] Resolve #176: list stashes in wf status command Also: * Add type predicate that checks whether a Maybe is a Some * Add ability for $api.Function.Array.Filter to narrow type --- loader/$api-Function-stream.fifty.ts | 2 -- loader/$api-Function-stream.js | 5 +--- loader/$api-Function.fifty.ts | 6 +++- loader/$api-Function.js | 4 +++ tools/wf/plugin-standard.jsh.js | 45 ++++++++++++++++++---------- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/loader/$api-Function-stream.fifty.ts b/loader/$api-Function-stream.fifty.ts index 03cac51e6..4b260a208 100644 --- a/loader/$api-Function-stream.fifty.ts +++ b/loader/$api-Function-stream.fifty.ts @@ -19,8 +19,6 @@ namespace slime.$api.fp { array: (ts: T[]) => Stream } - //flatMap: (map: (t: T) => R) => (stream: Stream>) => Stream - first: (ts: Stream) => Maybe find: { diff --git a/loader/$api-Function-stream.js b/loader/$api-Function-stream.js index ae9c5c6bf..20e56a457 100644 --- a/loader/$api-Function-stream.js +++ b/loader/$api-Function-stream.js @@ -101,10 +101,7 @@ $f.Stream.filter(predicate), $f.Stream.first ) - }//, - // flatMap: function(map) { - // throw new Error("Unimplemented"); - // } + } }); } //@ts-ignore diff --git a/loader/$api-Function.fifty.ts b/loader/$api-Function.fifty.ts index 8e89d9a43..c9258b6ef 100644 --- a/loader/$api-Function.fifty.ts +++ b/loader/$api-Function.fifty.ts @@ -418,11 +418,15 @@ namespace slime.$api.fp { from: (t: T) => Maybe map: (f: (t: T) => R) => (m: Maybe) => Maybe else: (f: () => T) => (m: Maybe) => T + present: (m: Maybe) => m is Some } } export interface Exports { Array: { - filter: (f: fp.Predicate) => (ts: T[]) => T[] + filter: { + (f: (t: T) => t is S): (ts: T[]) => S[] + (f: fp.Predicate): (ts: T[]) => T[] + } find: (f: fp.Predicate) => (ts: T[]) => T | undefined map: (f: (t: T) => R) => (ts: T[]) => R[] join: (s: string) => (elements: any[]) => string diff --git a/loader/$api-Function.js b/loader/$api-Function.js index e72960ccc..5c54cd2b6 100644 --- a/loader/$api-Function.js +++ b/loader/$api-Function.js @@ -170,6 +170,10 @@ if (maybe.present) return maybe.value; return f(); } + }, + /** @type { slime.$api.fp.Exports["Maybe"]["present"] } */ + present: function(m) { + return m.present; } } diff --git a/tools/wf/plugin-standard.jsh.js b/tools/wf/plugin-standard.jsh.js index b9f0829d2..1b22d1f32 100644 --- a/tools/wf/plugin-standard.jsh.js +++ b/tools/wf/plugin-standard.jsh.js @@ -194,22 +194,24 @@ } $exports.status = function(p) { - // /** @type { slime.jrunscript.tools.git.Command } */ - // var stashList = { - // invocation: function() { - // return { - // command: "stash", - // arguments: ["list"] - // } - // }, - // result: $api.Function.pipe( - // $api.Function.string.split("\n"), - // $api.Function.Array.map($api.Function.RegExp.exec(/^(.*)\:/)), - // function(p) { - // // will use flatMap when complete - // } - // ) - // } + /** @type { slime.jrunscript.tools.git.Command } */ + var stashList = { + invocation: function() { + return { + command: "stash", + arguments: ["list"] + } + }, + result: $api.Function.pipe( + $api.Function.string.split("\n"), + $api.Function.Array.map($api.Function.RegExp.exec(/^([^\:]+)(?:.*)$/)), + $api.Function.Array.filter($api.Function.Maybe.present), + $api.Function.Array.map($api.Function.property("value")), + $api.Function.Array.map(function(p) { + return { stash: p[1] }; + }) + ) + }; // TODO add option for offline var oRepository = jsh.wf.git.fetch(); @@ -245,7 +247,18 @@ }) ); if (output) jsh.shell.console(output); + + var stashes = fRepository.command(stashList).argument().run(); + if (stashes.length) { + jsh.shell.console(""); + jsh.shell.console("Stashes:"); + stashes.forEach(function(stash) { + jsh.shell.console(stash.stash); + }); + } + if (vsRemote && vsRemote.behind.length && !vsRemote.ahead.length && !vsRemote.paths) { + jsh.shell.console(""); jsh.shell.console("Fast-forwarding ..."); oRepository.merge({ ffOnly: true, name: base }); }