Skip to content

Commit

Permalink
Add primitive CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Sep 29, 2012
1 parent 8d96dca commit d6d5f98
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -3,4 +3,5 @@
erl_crash.dump
log
/priv/motd
sys.config
sys.config
/expm
9 changes: 6 additions & 3 deletions Makefile
@@ -1,9 +1,12 @@
all: ebin
all: expm

.PHONY: ebin

ebin:
mix do deps.get, compile
@mix do deps.get, compile

expm: ebin
@mix escriptize

start: ebin
@foreman start
@foreman start
43 changes: 43 additions & 0 deletions lib/cli.ex
@@ -0,0 +1,43 @@
defrecord Expm.CLI, repository: "http://expm.co", username: nil, password: nil do

def run(["list"], rec) do
run(["search", ""], rec)
end

def run(["search", kwd], rec) do
repo = repo(rec)
pkgs = Expm.Package.search repo, kwd
lc pkg inlist pkgs do
:io.format("~-20ts ~ts~n",[pkg.name, pkg.description])
end
end

def run(["spec",package], rec) do
repo = repo(rec)
case Enum.reverse(List.sort(Expm.Package.versions repo, package)) do
[] ->
IO.puts "No such package"
[version] ->
pkg = Expm.Package.fetch repo, package, version
IO.inspect pkg
end
end

def run(["publish"], rec) do
run(["publish", "package.exs"], rec)
end

def run(["publish", file], rec) do
pkg = Expm.Package.read(file)
IO.inspect pkg.publish(repo(rec))
end

def run(_, _) do
IO.puts "Invalid command"
end

defp repo(rec) do
Expm.Repository.HTTP.new(url: repository(rec),
username: username(rec), password: password(rec))
end
end
11 changes: 10 additions & 1 deletion lib/expm.ex
Expand Up @@ -12,4 +12,13 @@ defmodule Expm do
:application.set_env(:expm, :app_module, app_module)
:ok = Application.start(:expm)
end
end

def main(argv) do
argv = lc arg inlist argv, do: to_binary(arg)
{opts, commands} = OptionParser.parse(argv,
aliases: [
r: :repository,
])
Expm.CLI.new(opts).run(commands)
end
end
4 changes: 2 additions & 2 deletions lib/server/templates.ex
Expand Up @@ -94,11 +94,11 @@ defmodule Expm.Server.Templates do
<p>This repository is available over HTTP:</p>

<p>
<code>repo = Expm.Repository.HTTP.new url: "http://<%= @host %><%= @port %>"[, username: "...", password: "..."]</code>
<code>expm -r http://<%= @host %><%= @port %> list</code>
</p>
<p>To publish a package:</p>

<code>Expm.Package.publish repo, Expm.Package.read(filename // "package.exs") </code>
<code>expm --username ... --password ... -r http://<%= @host %><%= @port %> publish [package.exs]</code>
</div>
<hr>

Expand Down
4 changes: 3 additions & 1 deletion mix.exs
Expand Up @@ -4,7 +4,9 @@ defmodule Expm.Mixfile do
def project do
[ app: :expm,
version: System.cmd("git describe --always --tags"),
deps: deps ]
deps: deps,
escript_embed_elixir: true
]
end

# Configuration for the OTP application
Expand Down

0 comments on commit d6d5f98

Please sign in to comment.