Skip to content

Commit

Permalink
Rewrote eerie command, added new options. Fixed removing packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
josip committed Apr 11, 2010
1 parent 39a9bf1 commit fef7504
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 133 deletions.
199 changes: 93 additions & 106 deletions bin/eerie
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,132 +9,119 @@ Eerie do(
self _log(str, mode)))
)

Namespaces Env := Namespace clone
Eerie Env describe do(
setNamespace(Namespaces Env)
setRequiresClone(true)

createClone = method(args,
Eerie Env named(args removeFirst))

task("create") do(
describe("Creates a new environment.")
createClone = method(args,
self targetObj with(args removeFirst))

after(r, "Created #{self targetObj name} env." interpolate)
)

task("activate") do(
describe("Activates the environment, all binaries and addons in it will be loaded by default.")
after(env, "Activated #{env name} env." interpolate)
)

task("remove") do(
describe("Removes an env with all its packages.")
after(r, "#{self targetObj name} was removed." interpolate)
)

# TODO: Clone envs
#task("clone") do(
# describe("Creates a new env with packages of an existing one.")
# callsSlot("cloneAs")
#)
) done
Namespaces Env := Namespace clone do(
create := task(name,
"""Creates a new environment."""
Eerie Env with(name) create
"Created #{name} env." interpolate println)

activate := task(name,
"""Sets environment as default."""
Eerie Env named(name) activate
"Activated #{name} env." interpolate println)

remove := task(name,
"""Removes an env with all its packages."""
Eerie Env named(name) remove
"Env #{name} was removed." interpolate println)

active := task(
"""Prints the name of active env."""
Eerie activeEnv name println)
)

Eerie describe do(
setNamespace(Namespaces Env)

task("active") do(
describe("Prints the name of active environment.")
callsSlot("activeEnv")

after(env, env name)
)

task("list") do(
describe("Lists all available environments.")
callsSlot("envs")

after(envs,
envs map(env, if(env isActive, env name .. " *", env name))\
select(!= nil)\
select(exSlice(0, 1) != "_")\
sort)
returns(List, Map with("joinWith", "\n"))
envs = envs map(env,
if(env isActive, env name .. " [A]", env name))
envs select(!= nil)\
select(exSlice(0, 1) != "_")\
sort)

returns(List, Map with("joinWith", "\n",
"bullet", "*",
"indent", 1))
)
) done

Namespaces Pkg := Namespace clone
Eerie Package describe do(
setNamespace(Namespaces Pkg)
setRequiresClone(true)

createClone = method(args,
Eerie activeEnv packageNamed(args removeFirst))

task("install") do(
describe("Installs a new package.")
createClone = method(args,
Eerie Package fromUri(args removeFirst))

after(pkg,
"Package #{pkg name} has been installed." interpolate println

readme := pkg config at("meta") ?at("readme")
if(readme isNil,
""
,
readmeFile := File with(pkg path .. "/" .. readme)
readmeFile exists ifFalse(return(""))

"Opening readme file..." println
System sleep(2)

openCommand := if(System platform == "Darwin", "open", System getEnvironmentVariable("EDITOR"))
openCommand isNil ifTrue(openCommand = "more")

System system(openCommand .. " " .. readmeFile path)
""))
)

task("update") do(
describe("Updates the package and all of its submodules.")
after(result, "Package #{self targetObj name} has been updated." interpolate)
)

task("updateAll") do(
describe("Updates all packages within current env.")
setTargetObj(Eerie activeEnv)
callsSlot("packages")

after(packages, packages foreach(update); "")
)

task("remove") do(
describe("Removes the package.")
after(result, "Package #{self targetObj name} has been removed." interpolate)
)

task("list") do(
describe("Lists all packages installed within current env.")
setTargetObj(Eerie activeEnv)
callsSlot("packages")

after(pkgs, pkgs map(name))
returns(List, Map with("joinWith", "\n"))
)
) done
Namespaces Pkg := Namespace clone do(
install := task(uri,
"""Installs a new package."""
pkg := Eerie Package fromUri(uri)
pkg install
"Package #{pkg name} has been installed." interpolate println

readme := pkg config at("meta") ?at("readme")
readmeFile := File with(pkg path .. "/" .. readme)
readmeFile exists ifTrue(
"Opening readme file..." println
# Allows user to abort with Control+C
System sleep(2)

openCommand := if(System platform == "Darwin", "open", System getEnvironmentVariable("EDITOR"))
openCommand isNil ifTrue(openCommand = "most")

System system(openCommand .. " " .. readmeFile path)))

update := task(name,
"""Updates the package and all of its dependencies."""
Eerie activeEnv packageNamed(name) ?update
"Package #{name} has been updated." interpolate println)

updateAll := task(
"""Updates all packages within current env."""
Eerie activeEnv packages foreach(pkg,
pkg update ifTrue("#{pkg name} has been updated." interpolate println)))

remove := task(name,
"""Removes the package."""
Eerie activeEnv packageNamed(name) ?remove
"Package #{name} has been removed." interpolate println)

info := task(name,
"""Shows description of a package."""
pkg := Eerie activeEnv packageNamed(name)
pkg isNil ifTrue(
Exception raise("No such package exists."))

meta := pkg config at("meta")
maxKeySize := meta keys map(size) max + 2

meta foreach(key, value,
value isKindOf(List) ifTrue(value = value join(", "))
value isKindOf(Map) ifTrue(value = value asObject slotSummary)
key = (key asMutable makeFirstCharacterUppercase .. ":") alignLeft(maxKeySize, " ")
(key .. value) println))

list := task(
"""Lists all packages installed within current env."""
Eerie activeEnv packages foreach(pkg,
meta := pkg config at("meta")
(pkg name .. " @" .. meta at("version")) println
(" " .. meta at("description")) println))
)

Namespaces Default do(
selfUpdate := task(
"""Updates Eerie and its dependencies."""
Eerie Env named("_base") use
Eerie activeEnv packageNamed("Eerie") update)
Eerie usedEnv packageNamed("Eerie") update)

envs := Namespaces Env getSlot("list")
pkgs := Namespaces Pkg getSlot("list")
install := Namespaces Pkg getSlot("install")
remove := Namespaces Pkg getSlot("remove")
)

Namespaces Options do(
v := option(
"""Shows verbose output"""
Eerie log = Eerie getSlot("_log"))
)

Kano run
20 changes: 19 additions & 1 deletion io/Eerie.io
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
//metadoc Eerie category Utilites
//metadoc Eerie author Josip Lisec
//metadoc Eerie description Eerie is the package manager for Io.
Eerie := Object clone do(
//doc Eerie root Value of EERIEDIR system's environment variable.
root ::= System getEnvironmentVariable("EERIEDIR")
//doc Eerie tmpDir
tmpDir ::= root .. "/tmp"
# activeEnv will be set from Eerie/Env.io
//doc Eerie usedEnv Environment currently in use, not necessarily same as [[Eerie activeEnv]].
# usedEnv will be set from Eerie/Env.io
usedEnv ::= nil
//doc Eerie activeEnv Default environment. You probably need [[Eerie usedEnv]].
activeEnv ::= nil
configFile := nil
config ::= nil
configBackup ::= nil
//doc Eerie envs List of environmets
envs := List clone

//doc Eerie sh(cmd[, logFailure=true, dir=cwd]) Executes system command.
sh := method(cmd, logFailure, dir,
self log(cmd, "console")
dir isNil ifFalse(
Expand Down Expand Up @@ -41,6 +51,7 @@ Eerie := Object clone do(
"error", " ! ",
"console", " > ",
"output", "")
//doc Eerie log(message, mode) Displays the message to the user, mode can be "info", "error", "console" or "output".
log := method(str, mode,
mode ifNil(mode = "info")
((self _logMods at(mode)) .. str) interpolate(call sender) println)
Expand All @@ -59,23 +70,30 @@ Eerie := Object clone do(
self activeEnv use)
self)

//doc Eerie updateConfig(key, value) Updates config object.
updateConfig := method(key, value,
self config atPut(key, value)
self saveConfig)

//doc Eerie saveConfig
saveConfig := method(
self configFile close remove openForUpdating write(self config asJson)
self)

//doc Eerie revertConfig Reverts config to the state it was in before executing this script.
revertConfig := method(
self configFile close remove openForUpdating write(self configBackup)
self setConfig(Yajl parseJson(self configBackup)))
)

Eerie clone = Eerie do(
//doc Eerie Package [[Pacakge]]
doRelativeFile("Eerie/Package.io")
//doc Eerie PackageDownloader [[PackageDownloader]]
doRelativeFile("Eerie/PackageDownloader.io")
//doc Eerie PackageInstaller [[PackageInstaller]]
doRelativeFile("Eerie/PackageInstaller.io")
//doc Eerie Env [[Env]]
doRelativeFile("Eerie/Env.io")

init
Expand Down
2 changes: 1 addition & 1 deletion io/Eerie/AddonBuilder.io
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ AddonBuilder := Object clone do(
includePaths := method(
includePaths := List clone
includePaths appendSeq(libsFolder directories map(path) map(p, Path with(p, "_build/headers")))
includePaths appendSeq(depends addons map(n, (Eerie activeEnv path) .. "/addons/" .. n .. "/_build/headers"))
includePaths appendSeq(depends addons map(n, (Eerie usedEnv path) .. "/addons/" .. n .. "/_build/headers"))
includePaths
)

Expand Down
Loading

0 comments on commit fef7504

Please sign in to comment.