Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Initial commit; basic apps:info and apps:create working.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Nov 21, 2011
0 parents commit 9ba711d
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
/pom.xml
*jar
/lib
/classes
/native
/.lein-failures
/checkouts
/.lein-deps-sum
13 changes: 13 additions & 0 deletions README.md
@@ -0,0 +1,13 @@
# lein-heroku

A Leiningen plugin for managing your Heroku apps.

## Usage

FIXME: write

## License

Copyright © 2011 Heroku Inc.

Distributed under the Eclipse Public License, the same as Clojure.
8 changes: 8 additions & 0 deletions project.clj
@@ -0,0 +1,8 @@
(defproject lein-heroku "1.0.0-SNAPSHOT"
:description "Heroku plugin for Leiningen"
:dependencies [[lein-newnew "0.1.0"]
[com.heroku.api/heroku-api "0.1-SNAPSHOT"]
[com.heroku.api/heroku-httpclient "0.1-SNAPSHOT"]
[com.heroku.api/heroku-json-gson "0.1-SNAPSHOT"]
[clj-http "0.2.4"]]
:eval-in-leiningen true)
59 changes: 59 additions & 0 deletions src/leiningen/heroku.clj
@@ -0,0 +1,59 @@
(ns leiningen.heroku
(:require [clojure.java.io :as io]
[clj-http.core :as http]
[leiningen.help :as help])
(:import (com.heroku.api.command CommandConfig)
(com.heroku.api.command.login BasicAuthLogin)
(com.heroku.api.connection Connection HttpClientConnection)
(com.heroku.api HerokuAPI HerokuStack)))

(try ; Leiningen 2.0 compatibility
(use '[leiningen.core :only [abort]])
(catch Exception _
(use '[leiningen.main :only [abort]])))

(defn- read-password []
(.readPassword (System/console) "%s" (into-array ["Password: "])))

(defn- credentials-file []
(io/file (System/getProperty "user.home") ".heroku" "credentials"))

(defn- get-credentials []
(-> (credentials-file)
(slurp)
(.split "\n")))

(defn login [_ & args]
(println "Enter your Heroku credentials.")
(print "Email: ") (flush)
(let [email (read-line)
password (read-password)
command (BasicAuthLogin. email password)]
;; TODO: save to credentials-file
))

(defn api []
(when-not (.exists (credentials-file))
(login))
(let [[email key] (get-credentials)]
(-> (BasicAuthLogin. email key)
(HttpClientConnection.)
(HerokuAPI/with))))

(defn app-api []
;; TODO: depends on current directory; should we pass project args around?
(let [git-config (slurp (io/file ".git/config"))
[_ app-name] (re-find #"git@heroku.com:(.+).git" git-config)]
(.app (api) app-name)))

(defn ^{:no-project-needed true} heroku
"Manage Heroku apps."
[command & args]
(let [command-ns (str "leiningen.heroku." (first (.split command ":")))
_ (require (symbol command-ns))
subtask (ns-resolve (symbol command-ns) (symbol command))]
(try
;; TODO: help
(apply subtask args)
(catch Exception e
(abort (.getMessage e))))))
33 changes: 33 additions & 0 deletions src/leiningen/heroku/apps.clj
@@ -0,0 +1,33 @@
(ns leiningen.heroku.apps
(:require [leiningen.heroku :as heroku])
(:import (com.heroku.api.command.app AppList)
(com.heroku.api Heroku$Stack)))

(defn create [name]
(-> (heroku/api) (.newapp Heroku$Stack/Cedar name)))

(defn apps:create [name]
(let [response (create name)]
(println "Created app" (.getAppName response))))

(defn apps:destroy [])

(defn- space-key [k longest-key]
(apply str k ": " (repeat (- longest-key (count k)) " ")))

(defn apps:info []
(let [api (heroku/app-api)
info (.info api)
longest-key (apply max (map count (keys info)))]
(println "==" (.getAppName api))
(doseq [[k v] info]
(println (space-key k longest-key) v))))

(defn apps:open [])

(defn apps:rename [new-name])

(defn apps []
(println "= Heroku Applications")
(doseq [app (-> (heroku/api) .apps .getData)]
(println "*" (.get app "name"))))

0 comments on commit 9ba711d

Please sign in to comment.