Skip to content

Commit

Permalink
Migration WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Oct 21, 2024
1 parent 621ff9b commit 6af96e7
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 174 deletions.
50 changes: 25 additions & 25 deletions src/cli/actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object actions:
CliFrontEnd,
Terminal,
Stdio)
: ExitStatus raises UserError =
: Exit raises UserError =

tend:
val directories = Installer.candidateTargets().map(_.path)
Expand All @@ -80,11 +80,11 @@ object actions:

if !noTabCompletions then Out.println(TabCompletions.install(force = true).communicate)

ExitStatus.Ok
Exit.Ok

.remedy:
case InstallError(message) => abort(UserError(message.communicate))
case DismissError() => ExitStatus.Fail(1)
case DismissError() => Exit.Fail(1)

def batch(force: Boolean, noTabCompletions: Boolean)
(using DaemonService[?],
Expand All @@ -95,16 +95,16 @@ object actions:
WorkingDirectory,
HomeDirectory,
Effectful)
: ExitStatus raises UserError =
: Exit raises UserError =

tend:
log(Installer.install(force).communicate)
if !noTabCompletions then info(TabCompletions.install(force = true).communicate)
ExitStatus.Ok
Exit.Ok
.remedy:
case InstallError(message) => abort(UserError(message.communicate))

def clean(all: Boolean)(using FrontEnd, Installation): ExitStatus raises UserError =
def clean(all: Boolean)(using FrontEnd, Installation): Exit raises UserError =
import filesystemOptions.
{doNotCreateNonexistent, doNotDereferenceSymlinks, deleteRecursively}

Expand All @@ -118,25 +118,25 @@ object actions:

val size = safely(size0 - installation.cache.as[Directory].size()).or(0.b)
log(t"$size was cleaned up")
ExitStatus.Ok
Exit.Ok

object cache:
def clean()(using FrontEnd): ExitStatus raises UserError =
def clean()(using FrontEnd): Exit raises UserError =
log(m"Cleaning the cache")
Cache.clear()
ExitStatus.Ok
Exit.Ok

def about()(using FrontEnd, Monitor): ExitStatus raises UserError = Cache.about.pipe: cache =>
def about()(using FrontEnd, Monitor): Exit raises UserError = Cache.about.pipe: cache =>
info
(m"""
The cache contains ${cache.ecosystems} ecosystems, ${cache.snapshots} repository snapshots,
${cache.workspaces} workspaces and ${cache.files} files, totalling ${cache.dataSize}.
""")
ExitStatus.Ok
Exit.Ok

object universe:

def show()(using Internet, WorkingDirectory, Monitor, Log[Display], FrontEnd, Stdio): ExitStatus raises UserError =
def show()(using Internet, WorkingDirectory, Monitor, Log[Display], FrontEnd, Stdio): Exit raises UserError =
val rootWorkspace = tend(Workspace()).remedy:
case WorkspaceError(reason) =>
abort(UserError(m"The workspace could not be constructed because $reason"))
Expand Down Expand Up @@ -167,7 +167,7 @@ object actions:
e"$DeepSkyBlue(${vault.name})")

log(table.tabulate(projects))
ExitStatus.Ok
Exit.Ok

object project:
def publish(projectId: ProjectId, streamId: Optional[StreamId])
Expand All @@ -178,7 +178,7 @@ object actions:
GitCommand,
Log[Display],
Internet)
: ExitStatus raises UserError =
: Exit raises UserError =
import filesystemOptions.doNotCreateNonexistent

val build = tend(Workspace().build).remedy:
Expand Down Expand Up @@ -224,13 +224,13 @@ object actions:
case ExecError(_, _, _) => abort(UserError(m"An execution error occurred"))
case ReleaseError(reason) => abort(UserError(m"There was a problem with the release: $reason"))

ExitStatus.Ok
Exit.Ok
.or:
Out.println(t"Project $projectId is not defined in this workspace")
ExitStatus.Fail(1)
Exit.Fail(1)

object build:
def initialize(directory: Path)(using CliFrontEnd): ExitStatus raises UserError =
def initialize(directory: Path)(using CliFrontEnd): Exit raises UserError =
if (directory / p".fury").exists()
then abort(UserError(m"A build already exists in this directory"))

Expand All @@ -244,10 +244,10 @@ object actions:
LineEditor(t"").ask: description =>
Out.println(e"You chose $Bold($id), $Bold($name), and $Bold($description)")

ExitStatus.Ok
Exit.Ok

.remedy:
case DismissError() => ExitStatus.Fail(1)
case DismissError() => Exit.Fail(1)

def run(target: Target, watch: Boolean, force: Boolean, concise: Boolean)
(using CliFrontEnd,
Expand All @@ -260,7 +260,7 @@ object actions:
GitCommand,
SystemProperties,
Environment)
: ExitStatus raises UserError =
: Exit raises UserError =

import filesystemOptions.doNotCreateNonexistent
import filesystemOptions.dereferenceSymlinks
Expand Down Expand Up @@ -312,14 +312,14 @@ object actions:
case WatchError() => abort(UserError(m"There was an error filewatching"))
case PathError(text, expect) => abort(UserError(m"An invalid path was encountered"))

ExitStatus.Ok
Exit.Ok

def invalidSubcommand(command: Argument)(using FrontEnd): ExitStatus raises UserError =
def invalidSubcommand(command: Argument)(using FrontEnd): Exit raises UserError =
abort(UserError(m"${command()} is not a valid subcommand."))

def missingSubcommand()(using FrontEnd): ExitStatus raises UserError =
def missingSubcommand()(using FrontEnd): Exit raises UserError =
abort(UserError(m"No subcommand was specified."))

def versionInfo()(using FrontEnd): ExitStatus =
def versionInfo()(using FrontEnd): Exit =
log(m"Fury version 1.0")
ExitStatus.Ok
Exit.Ok
44 changes: 22 additions & 22 deletions src/cli/cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def main(): Unit =
if interactive then actions.install.installInteractive(force, noTabCompletions)
else actions.install.batch(force, noTabCompletions)

ExitStatus.Ok
Exit.Ok

case Init() :: _ =>
execute:
Expand All @@ -171,7 +171,7 @@ def main(): Unit =
execute:
frontEnd:
log(installation.config.inspect)
ExitStatus.Ok
Exit.Ok

case Clean() :: _ =>
val all: Boolean = All().present
Expand All @@ -189,7 +189,7 @@ def main(): Unit =
case Nil =>
execute:
Out.println(t"Module has not been specified")
ExitStatus.Fail(1)
Exit.Fail(1)

case target :: _ =>
val online = Offline().absent
Expand Down Expand Up @@ -224,7 +224,7 @@ def main(): Unit =
UserError(m"An execution error occurred")

.within:
actions.build.run(target().decodeAs[Target], watch, force, concise)
actions.build.run(target().decode[Target], watch, force, concise)

daemon:
terminal.events.stream.each:
Expand All @@ -248,14 +248,14 @@ def main(): Unit =
Out.println:
e"Command $Italic(${command.vouch(using Unsafe)()}) was not recognized."

ExitStatus.Fail(1)
Exit.Fail(1)

case Ecosystem() :: subcommands => subcommands match
case Publish() :: target => target match
case Nil =>
execute:
Out.println(t"Project has not been specified")
ExitStatus.Fail(1)
Exit.Fail(1)

case projectId :: _ =>
val workspace = safely(Workspace())
Expand All @@ -282,28 +282,28 @@ def main(): Unit =
case ExecError(_, _, _) =>
UserError(m"An execution error occurred")

.within(actions.project.publish(projectId().decodeAs[ProjectId], Stream()))
.within(actions.project.publish(projectId().decode[ProjectId], Stream()))


case _ =>
execute:
Out.println(t"Unknown command")
ExitStatus.Fail(1)
Exit.Fail(1)

case Shutdown() :: Nil => execute:
FrontEnd.shutdown()
service.shutdown()
ExitStatus.Ok
Exit.Ok

case Nil =>
execute:
tend:
case WorkspaceError(_) =>
ExitStatus.Fail(1)
Exit.Fail(1)
.within:
val workspace = Workspace()
Out.println(Workspace().build.actions.prim.inspect)
ExitStatus.Ok
Exit.Ok

case subcommands =>
if Version().present then execute(frontEnd(actions.versionInfo())) else
Expand All @@ -313,7 +313,7 @@ def main(): Unit =
if subcommand.present && subcommand.lay(false)(_().contains(t"/")) then execute:
unsafely:
Out.println(e"Executing script $Bold(${subcommand.vouch()})...")
ExitStatus.Fail(1)
Exit.Fail(1)
else
val online = Offline().absent
val watch = Watch().present
Expand All @@ -324,7 +324,7 @@ def main(): Unit =
subcommand.let(_.suggest(previous ++ workspace.build.actions.map(_.suggestion)))

execute:
workspace.lay(ExitStatus.Fail(2)): workspace =>
workspace.lay(Exit.Fail(2)): workspace =>
subcommand.let: subcommand =>
tend:
case InvalidRefError(ref, _) =>
Expand Down Expand Up @@ -362,10 +362,10 @@ def main(): Unit =

tend:
buildTask.await().also(Out.print(t"\e[?25h"))
ExitStatus.Ok
Exit.Ok
.remedy:
case ConcurrencyError(_) =>
ExitStatus.Fail(1)
Exit.Fail(1)

tend(main.await()).remedy:
case ConcurrencyError(_) =>
Expand All @@ -374,28 +374,28 @@ def main(): Unit =
.or:
subcommand.let(frontEnd(actions.invalidSubcommand(_))).or:
Out.println(t"No subcommand was specified.")
ExitStatus.Fail(1)
Exit.Fail(1)

.recover: userError =>
execute:
Out.println(userError.message)
Log.fail(userError)
ExitStatus.Fail(4)
Exit.Fail(4)

.remedy:
// case InitError(message) =>
// println(message)
// ExitStatus.Fail(2)
// Exit.Fail(2)

// case error: IoError =>
// println(error.message)
// ExitStatus.Fail(2)
// Exit.Fail(2)

case ConcurrencyError(reason) =>
println(m"There was a concurrency error")
ExitStatus.Fail(3)
Exit.Fail(3)

def about()(using stdio: Stdio): ExitStatus =
def about()(using stdio: Stdio): Exit =
safely:
Out.println:
stdio.termcap.color match
Expand Down Expand Up @@ -447,4 +447,4 @@ def about()(using stdio: Stdio): ExitStatus =
Out.println:
e" ${Italic}(${Properties.os.name()} ${Properties.os.version()}, ${Properties.os.arch()})\n"

ExitStatus.Ok
Exit.Ok
Loading

0 comments on commit 6af96e7

Please sign in to comment.