Skip to content

Commit

Permalink
Resolve #176: list stashes in wf status command
Browse files Browse the repository at this point in the history
Also:
* Add type predicate that checks whether a Maybe is a Some
* Add ability for $api.Function.Array.Filter to narrow type
  • Loading branch information
davidpcaldwell committed Jun 26, 2022
1 parent bd94ed1 commit 12538cd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
2 changes: 0 additions & 2 deletions loader/$api-Function-stream.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ namespace slime.$api.fp {
array: <T>(ts: T[]) => Stream<T>
}

//flatMap: <T,R>(map: (t: T) => R) => (stream: Stream<Maybe<T>>) => Stream<R>

first: <T>(ts: Stream<T>) => Maybe<T>

find: {
Expand Down
5 changes: 1 addition & 4 deletions loader/$api-Function-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@
$f.Stream.filter(predicate),
$f.Stream.first
)
}//,
// flatMap: function(map) {
// throw new Error("Unimplemented");
// }
}
});
}
//@ts-ignore
Expand Down
6 changes: 5 additions & 1 deletion loader/$api-Function.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,15 @@ namespace slime.$api.fp {
from: <T>(t: T) => Maybe<T>
map: <T,R>(f: (t: T) => R) => (m: Maybe<T>) => Maybe<R>
else: <T>(f: () => T) => (m: Maybe<T>) => T
present: <T>(m: Maybe<T>) => m is Some<T>
}
}
export interface Exports {
Array: {
filter: <T>(f: fp.Predicate<T>) => (ts: T[]) => T[]
filter: {
<T,S extends T>(f: (t: T) => t is S): (ts: T[]) => S[]
<T>(f: fp.Predicate<T>): (ts: T[]) => T[]
}
find: <T>(f: fp.Predicate<T>) => (ts: T[]) => T | undefined
map: <T,R>(f: (t: T) => R) => (ts: T[]) => R[]
join: (s: string) => (elements: any[]) => string
Expand Down
4 changes: 4 additions & 0 deletions loader/$api-Function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
45 changes: 29 additions & 16 deletions tools/wf/plugin-standard.jsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,24 @@
}

$exports.status = function(p) {
// /** @type { slime.jrunscript.tools.git.Command<void,{ stash: string }> } */
// 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<void,{ stash: string }[]> } */
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();
Expand Down Expand Up @@ -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 });
}
Expand Down

0 comments on commit 12538cd

Please sign in to comment.