Skip to content

Commit

Permalink
np4: Add reopen command (#264)
Browse files Browse the repository at this point in the history
* np4: Add reopen support to p4 runner

* np4: Add reopen command
  • Loading branch information
BastianBlokland authored Jul 8, 2022
1 parent 12a76fe commit f08f068
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utilities/np4/app.ns
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import "cmd/describe.ns"
import "cmd/diff.ns"
import "cmd/grep.ns"
import "cmd/log.ns"
import "cmd/reopen.ns"
import "cmd/setup.ns"
import "cmd/status.ns"
import "cmd/streams.ns"

cli(cliCmd("status", statusCmd, "Print the status of the current workspace"),
cliCmd("setup", setupCmd, "Set a workspace up for use with np4"),
cliCmd("log", logCmd, "Print the most recent submitted changes"),
cliCmd("reopen", reopenCmd, "Reopen files in the given change"),
cliCmd("describe", describeCmd, "Print information about a specific change"),
cliCmd("log", logCmd, "Print the most recent submitted changes"),
cliCmd("diff", diffCmd, "Print file differences"),
cliCmd("grep", grepCmd, "Search for files with content matching the specified pattern"),
cliCmd("streams", streamsCmd, "Print a graph of all the streams on the server"),
cliCmd("setup", setupCmd, "Set a workspace up for use with np4"),
cliAppInfo(
"Novus P4", "Convenience wrapper around the p4 perforce client.",
Version(0, 14, 0)))
Version(0, 15, 0)))
37 changes: 37 additions & 0 deletions utilities/np4/cmd/reopen.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import "std.ns"

import "../perforce/runner.ns"

import "../utils/shared-writers.ns"
import "../utils/style.ns"
import "../utils/tracer.ns"

// -- Writers.

fun reopenOutputWriter() -> Writer{List{P4ReopenResult}}
(
listWriter(depotPathWriter() & newlineWriter())
).map(lambda (List{P4ReopenResult} r) r.map(lambda (P4ReopenResult result) result.depotFile))


// -- Driver.

struct ReopenSettings =
bool noColor,
bool trace,
CliPositional{P4Change} change,
CliPositional{P4Path} path

fun cliDefaults(Type{ReopenSettings} t)
CliDefault("path", "//...") :: List{CliDefault}()

act reopenCmd(ReopenSettings s) -> Option{Error}
c = consoleOpen().failOnError();
styleCtx = StyleCtx(!s.noColor && c.allowColor());
tracer = s.trace ? p4ConsoleTracer(c, styleCtx) : P4Tracer();
writer = reopenOutputWriter();
resultsOrErr = loadConfig().map(impure lambda (Config cfg)
p4Reopen(P4RunContext(cfg, tracer), s.change.val, s.path.val)
);
if resultsOrErr as Error err -> err
if resultsOrErr as List{P4ReopenResult} results -> c.writeOut(writer, results)
7 changes: 7 additions & 0 deletions utilities/np4/perforce/data/reopen.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "std.ns"

import "file.ns"

// -- Types.

struct P4ReopenResult = P4DepotPath depotFile
4 changes: 4 additions & 0 deletions utilities/np4/perforce/runner.ns
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "std.ns"
import "data/change.ns"
import "data/file.ns"
import "data/grep.ns"
import "data/reopen.ns"
import "data/resolve.ns"
import "data/stream.ns"
import "data/var.ns"
Expand Down Expand Up @@ -198,3 +199,6 @@ act p4Grep(P4RunContext ctx, string pattern, bool caseSensitive, List{P4Path} pa

act p4Where(P4RunContext ctx, P4DepotPath depotPath) -> Either{P4FileLocation, Error}
ctx.p4Run("where" :: depotPath.string(), Type{P4FileLocation}())

act p4Reopen(P4RunContext ctx, P4Change change, P4Path path) -> Either{List{P4ReopenResult}, Error}
ctx.p4RunMany("reopen" :: "-c" :: change.string() :: path.string(), Type{P4ReopenResult}())

0 comments on commit f08f068

Please sign in to comment.