nachos 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-rc2
@@ -1,14 +1,21 @@
1
- = nachos
1
+ Nachos
2
+ ================================
2
3
 
3
- Description goes here.
4
+ Because everyone loves Nachos!
4
5
 
5
- == Workflow
6
+ Sync your watched repos with Github. Manage them and stuff. Never leave wifi again without all the codes you care about, local.
7
+
8
+ And more.
9
+
10
+ Workflow
11
+ ================================
6
12
 
7
13
  * watch a project on github
8
14
  * run 'nachos sync'
9
15
  * magic - it is now up to date in your local repo and ready to go
10
16
 
11
- == Note on Patches/Pull Requests
17
+ Note on Patches/Pull Requests
18
+ ================================
12
19
 
13
20
  * Fork the project.
14
21
  * Make your feature addition or bug fix.
@@ -18,6 +25,6 @@ Description goes here.
18
25
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
19
26
  * Send me a pull request. Bonus points for topic branches.
20
27
 
21
- == Copyright
22
-
28
+ Copyright
29
+ --------------------------------
23
30
  Copyright (c) 2010 Rob Sanheim. See LICENSE for details.
data/lib/nachos/cli.rb CHANGED
@@ -1,76 +1,35 @@
1
1
  class Nachos::CLI < Thor
2
2
 
3
- LGHCONF = "http://github.com/guides/local-github-config"
4
- GIT_CONFIG = Hash.new do |cache, cmd|
5
- result = %x{git #{cmd}}.chomp
6
- cache[cmd] = $?.success? && !result.empty? ? result : nil
3
+ attr_reader :config, :main
4
+ class_option :dry_run, :type => :boolean, :default => false, :desc => "If specified, the converter will just print the commands and not actually execute them"
5
+
6
+ def initialize(*args)
7
+ @main = Nachos::Main.new(self)
8
+ super
7
9
  end
8
10
 
9
11
  desc "info", "Displays current setup for Nachos"
10
12
  def info
11
- shell.say <<-EOL
12
- You are running Nachos #{Nachos::VERSION} as #{github_user}.
13
- #{github_summary}
14
- Current configuration: #{config}
15
- EOL
13
+ shell.say main.info
16
14
  end
17
15
 
18
16
  desc "watched", "Display your watched repos on Github"
19
17
  def watched
20
- github.watched.each do |repo|
18
+ main.watched.each do |repo|
21
19
  shell.say "#{repo.owner}/#{repo.name} - #{repo.description}"
22
20
  end
23
21
  end
24
22
 
25
23
  desc "sync", "Sync repositories"
26
24
  def sync
27
- repos = github.watched
28
- shell.say "About to sync #{repos.size} repositories"
29
- repos.each do |repo|
30
- system Hub("clone #{repo.url}").command
31
- end
25
+ shell.say main.github_summary
26
+ main.sync
32
27
  end
33
28
 
34
29
  private
35
30
 
36
- def github_summary
37
- "You have #{github.watched.size} watched repos, and #{github.client.list_repos.size} owned repos."
38
- end
39
-
40
- def config
41
- config_path.exist? ? load_config : "No config found - run nachos config to create one"
42
- end
43
-
44
- def config_path
45
- Pathname(ENV["HOME"]).join(".nachos")
46
- end
47
-
48
- def load_config
49
- YAML.load_file(config_path)
50
- end
51
-
52
- def github
53
- @github ||= Nachos::Github.new(github_user, github_token)
31
+ def dry_run?
32
+ options[:dry_run]
54
33
  end
55
-
56
- # Either returns the GitHub user as set by git-config(1) or aborts
57
- # with an error message.
58
- def github_user(fatal = true)
59
- if user = GIT_CONFIG['config github.user']
60
- user
61
- elsif fatal
62
- abort("** No GitHub user set. See #{LGHCONF}")
63
- end
64
- end
65
-
66
- def github_token(fatal = true)
67
- if token = GIT_CONFIG['config github.token']
68
- token
69
- elsif fatal
70
- abort("** No GitHub token set. See #{LGHCONF}")
71
- end
72
- end
73
-
74
34
 
75
-
76
35
  end
@@ -0,0 +1,33 @@
1
+ class Nachos
2
+ class Config
3
+
4
+ def repo_root
5
+ Pathname(config.repo_root)
6
+ end
7
+
8
+ def config
9
+ config_exists? ? load_config : default_config
10
+ end
11
+
12
+ def display_config
13
+ config_exists? ? load_config : "No config found - run nachos config to create one"
14
+ end
15
+
16
+ def config_exists?
17
+ config_path.exist?
18
+ end
19
+
20
+ def config_path
21
+ Pathname(ENV["HOME"]).join(".nachos")
22
+ end
23
+
24
+ def default_config
25
+ @default_config ||= Hashie::Mash.new("repo_root" => "#{ENV["HOME"]}/src")
26
+ end
27
+
28
+ def load_config
29
+ Hashie::Mash.new(YAML.load_file(config_path))
30
+ end
31
+
32
+ end
33
+ end
data/lib/nachos/github.rb CHANGED
@@ -1,17 +1,45 @@
1
1
  class Nachos
2
2
 
3
- class Github
4
- attr_reader :client
5
-
6
- def initialize(github_user, github_token)
7
- @client = Octopussy::Client.new(:login => github_user, :token => github_token)
3
+ module Github
4
+ LGHCONF = "http://github.com/guides/local-github-config"
5
+ GIT_CONFIG = Hash.new do |cache, cmd|
6
+ result = %x{git #{cmd}}.chomp
7
+ cache[cmd] = $?.success? && !result.empty? ? result : nil
8
8
  end
9
+
10
+ attr_reader :client
9
11
 
10
12
  def watched
11
13
  client.watched.sort_by do |repo|
12
14
  [repo["owner"], repo["name"]].join("/")
13
15
  end
14
16
  end
17
+
18
+ # Either returns the GitHub user as set by git-config(1) or aborts
19
+ # with an error message.
20
+ def github_user(fatal = true)
21
+ if user = GIT_CONFIG['config github.user']
22
+ user
23
+ elsif fatal
24
+ abort("** No GitHub user set. See #{LGHCONF}")
25
+ end
26
+ end
27
+
28
+ def github_token(fatal = true)
29
+ if token = GIT_CONFIG['config github.token']
30
+ token
31
+ elsif fatal
32
+ abort("** No GitHub token set. See #{LGHCONF}")
33
+ end
34
+ end
35
+
36
+ def github_summary
37
+ "You have #{watched.size} watched repos, and #{client.list_repos.size} owned repos."
38
+ end
39
+
40
+ def client
41
+ @client ||= Octopussy::Client.new(:login => github_user, :token => github_token)
42
+ end
15
43
 
16
44
  end
17
45
  end
data/lib/nachos/main.rb CHANGED
@@ -1,4 +1,69 @@
1
- module Nachos
1
+ class Nachos
2
2
  class Main
3
+ extend Forwardable
4
+ include Nachos::Github
5
+ def_delegators :cli, :shell, :dry_run?
6
+ def_delegators :config, :config
7
+ attr_reader :cli, :config
8
+
9
+ def initialize(cli)
10
+ @cli = cli
11
+ @config = Nachos::Config.new
12
+ end
13
+
14
+ def info
15
+ %[You are running Nachos #{Nachos::VERSION} as #{github_user}.
16
+ #{github_summary}
17
+ Current configuration: #{config.display_config}]
18
+ end
19
+
20
+ def sync
21
+ chdir config.repo_root do
22
+ watched.each { |repo| sync_repo(repo) }
23
+ end
24
+ end
25
+
26
+ def chdir(dir)
27
+ shell.say_status :inside, dir
28
+ if dry_run?
29
+ yield
30
+ else
31
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
32
+ FileUtils.cd(dir) { yield }
33
+ end
34
+ end
35
+
36
+ def sync_repo(repo)
37
+ git_url = repo.url.gsub("http", "git")
38
+ path = repo_path(repo)
39
+ if repo_exists?(repo)
40
+ chdir(path) do
41
+ run Hub("fetch").command
42
+ end
43
+ else
44
+ run Hub("clone #{git_url} #{repo.owner}-#{repo.name}").command
45
+ end
46
+ end
47
+
48
+ def repo_path(repo)
49
+ Pathname(config.repo_root.join("#{repo.owner}-#{repo.name}"))
50
+ end
51
+
52
+ def repo_exists?(repo)
53
+ repo_path(repo).directory?
54
+ end
55
+
56
+ def Hub(args)
57
+ Hub::Runner.new(*args.split(' '))
58
+ end
59
+
60
+ def run(cmd)
61
+ if dry_run?
62
+ say cmd
63
+ else
64
+ system cmd
65
+ end
66
+ end
67
+
3
68
  end
4
69
  end
@@ -1,3 +1,3 @@
1
1
  class Nachos
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/nachos.rb CHANGED
@@ -4,28 +4,23 @@ require "thor"
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
5
 
6
6
  require 'nachos/version'
7
+ require 'nachos/config'
7
8
  require 'nachos/cli'
8
9
  require 'nachos/github'
10
+ require 'nachos/main'
9
11
 
10
12
  class Nachos
11
13
 
12
- attr_reader :args, :command
13
- attr_accessor :out, :err, :exit_code
14
+ attr_reader :args
14
15
 
15
16
  def initialize(*args)
16
17
  @args = args
17
- @command = args.first || "help"
18
- @exit_code = 0
19
18
  end
20
19
 
21
20
  def self.execute(*args)
22
21
  new(*args).execute
23
22
  end
24
23
 
25
- def runner
26
- @runner ||= Runner.new
27
- end
28
-
29
24
  def execute
30
25
  Nachos::CLI.start
31
26
  exit 0
data/nachos.gemspec CHANGED
@@ -5,24 +5,25 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nachos}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rob Sanheim"]
12
- s.date = %q{2010-08-06}
12
+ s.date = %q{2010-08-13}
13
13
  s.default_executable = %q{nachos}
14
14
  s.description = %q{Because everyone loves Nachos!}
15
15
  s.email = %q{rsanheim@gmail.com}
16
16
  s.executables = ["nachos"]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE",
19
- "README.rdoc"
19
+ "README.markdown"
20
20
  ]
21
21
  s.files = [
22
22
  ".document",
23
23
  ".gitignore",
24
+ ".rvmrc",
24
25
  "LICENSE",
25
- "README.rdoc",
26
+ "README.markdown",
26
27
  "Rakefile",
27
28
  "bin/nachos",
28
29
  "features/nachos.feature",
@@ -31,12 +32,15 @@ Gem::Specification.new do |s|
31
32
  "features/support/fakeweb/fakes.rb",
32
33
  "lib/nachos.rb",
33
34
  "lib/nachos/cli.rb",
35
+ "lib/nachos/config.rb",
34
36
  "lib/nachos/github.rb",
35
37
  "lib/nachos/main.rb",
36
38
  "lib/nachos/version.rb",
37
39
  "nachos.gemspec",
38
40
  "spec/nachos/cli_spec.rb",
41
+ "spec/nachos/config_spec.rb",
39
42
  "spec/nachos/github_spec.rb",
43
+ "spec/nachos/main_spec.rb",
40
44
  "spec/nachos_spec.rb",
41
45
  "spec/spec_helper.rb"
42
46
  ]
@@ -47,7 +51,9 @@ Gem::Specification.new do |s|
47
51
  s.summary = %q{Nachos - sync and stuff with Github}
48
52
  s.test_files = [
49
53
  "spec/nachos/cli_spec.rb",
54
+ "spec/nachos/config_spec.rb",
50
55
  "spec/nachos/github_spec.rb",
56
+ "spec/nachos/main_spec.rb",
51
57
  "spec/nachos_spec.rb",
52
58
  "spec/spec_helper.rb"
53
59
  ]
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Nachos::CLI do
4
4
  it "works" do
5
- Nachos::CLI.any_instance.stubs(:github_user).returns("johndoe")
5
+ Nachos::Main.any_instance.stubs(:github_user).returns("johndoe")
6
6
  watched_repos = []
7
7
  names = %w[zaphod matt aaron]
8
8
  3.to_i.times do |i|
@@ -29,24 +29,43 @@ describe Nachos::CLI do
29
29
 
30
30
  describe "info" do
31
31
  before do
32
- Thor::Base.shell = FakeShell
32
+ @orig_shell, Thor::Base.shell = Thor::Base.shell, FakeShell
33
+ end
34
+
35
+ after do
36
+ Thor::Base.shell = @orig_shell
33
37
  end
34
38
 
35
- it "loads config and displays it, if found" do
39
+ it "displays info from main" do
36
40
  cli = Nachos::CLI.new
37
- cli.stubs(:github_summary).returns("You have n repos...")
38
- cli.stubs(:config_path).returns(mock(:exist? => true))
39
- cli.stubs(:load_config).returns("config here")
41
+ cli.stubs(:main).returns(mock(:info => "info here"))
40
42
  cli.invoke(:info)
41
- cli.shell.output.should include("Current configuration: config here")
43
+ cli.shell.output.should include("info here")
44
+ end
45
+ end
46
+
47
+ describe "sync" do
48
+ before do
49
+ @orig_shell, Thor::Base.shell = Thor::Base.shell, FakeShell
50
+ end
51
+
52
+ after do
53
+ Thor::Base.shell = @orig_shell
42
54
  end
43
55
 
44
- it "tells user there is no config yet" do
45
- Thor::Base.shell = FakeShell
56
+ it "calls sync on main" do
46
57
  cli = Nachos::CLI.new
47
- cli.stubs(:github_summary).returns("You have n repos...")
48
- cli.invoke(:info)
49
- cli.shell.output.should include("No config found - run nachos config to create one")
58
+ main = stub_everything(:github_summary => "")
59
+ main.expects(:sync)
60
+ cli.stubs(:main).returns(main)
61
+ cli.invoke(:sync)
62
+ end
63
+
64
+ it "displays summary sync info" do
65
+ cli = Nachos::CLI.new
66
+ cli.stubs(:main).returns(stub_everything(:github_summary => "sync summary"))
67
+ cli.invoke(:sync)
68
+ cli.shell.output.should include("sync summary")
50
69
  end
51
70
  end
52
71
  end
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Nachos::Config do
4
+
5
+ describe "repo_root" do
6
+ before { Nachos::Config.any_instance.stubs(:config_exists?).returns(false) }
7
+
8
+ it "prefers configured path" do
9
+ config = Nachos::Config.new
10
+ config.config.repo_root = "/here/is/configured/path"
11
+ config.repo_root.should == Pathname("/here/is/configured/path")
12
+ end
13
+
14
+ it "uses default path if not otherwise configured" do
15
+ config = Nachos::Config.new
16
+ config.repo_root.should == Pathname(ENV["HOME"]).join("src")
17
+ end
18
+ end
19
+
20
+ describe "config" do
21
+ it "uses 'nil' config if no config found" do
22
+ YAML.stubs(:load_config).returns(nil)
23
+ Nachos::Config.new.config.anything.should == nil
24
+ end
25
+
26
+ it "wraps loaded yaml in a mashie thing" do
27
+ YAML.stubs(:load_config).returns({:somethign => "foo"})
28
+ config = Nachos::Config.new
29
+ config.config.should be_instance_of(Hashie::Mash)
30
+ end
31
+ end
32
+
33
+ end
@@ -1,26 +1,4 @@
1
1
  require "spec_helper"
2
2
 
3
- describe Nachos::CLI do
4
- it "sorts watched repos" do
5
- watched_repos = []
6
- repos = %w[zaphod/beta zaphod/aardvark matt/foo aaron/baz]
7
- repos.each do |repo|
8
- owner, name = repo.split("/")
9
- watched_repos << {
10
- "url" => "http://github.com/#{repo}",
11
- "name" => name,
12
- "owner" => owner
13
- }
14
- end
15
- body = { "repositories" => watched_repos }.to_json
16
- url = "http://github.com/api/v2/json/repos/watched/johndoe?"
17
- FakeWeb.register_uri(:get, url, :body => body)
18
-
19
- github = Nachos::Github.new("johndoe", "token")
20
- github.watched.map {|r| r["url"] }.should == %w[
21
- http://github.com/aaron/baz
22
- http://github.com/matt/foo
23
- http://github.com/zaphod/aardvark
24
- http://github.com/zaphod/beta]
25
- end
3
+ describe Nachos::Github do
26
4
  end
@@ -0,0 +1,39 @@
1
+ require "spec_helper"
2
+
3
+ describe Nachos::Main do
4
+
5
+ describe "info" do
6
+ it "shows summary of what is up" do
7
+ main = Nachos::Main.new(Nachos::CLI.new)
8
+ main.stubs(:github_user => "jdoe")
9
+ main.stubs(:github_summary => "github summary")
10
+ main.info.should include("jdoe")
11
+ main.info.should include(Nachos::VERSION)
12
+ main.info.should include("github summary")
13
+ end
14
+ end
15
+
16
+ describe "sync" do
17
+ it "syncs all repos" do
18
+ main = Nachos::Main.new(Nachos::CLI.new)
19
+ main.stubs(:watched).returns([])
20
+ main.sync
21
+ end
22
+ end
23
+
24
+ describe "repo_exists?" do
25
+ it "returns true if dir exists" do
26
+ Pathname.any_instance.expects(:directory?).returns(true)
27
+ repo = Hashie::Mash.new(:owner => "jdoe", :name => "project")
28
+ main = Nachos::Main.new(Nachos::CLI.new)
29
+ main.repo_exists?(repo).should be_true
30
+ end
31
+
32
+ it "returns false if dir does not exist" do
33
+ Pathname.any_instance.expects(:directory?).returns(false)
34
+ repo = Hashie::Mash.new(:owner => "jdoe", :name => "project")
35
+ main = Nachos::Main.new(Nachos::CLI.new)
36
+ main.repo_exists?(repo).should be_false
37
+ end
38
+ end
39
+ end
data/spec/nachos_spec.rb CHANGED
@@ -1,4 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Nachos do
4
+ describe "execute" do
5
+ it "calls start on CLI" do
6
+ Nachos::CLI.expects(:start)
7
+
8
+ nachos = Nachos.new
9
+ nachos.stubs(:exit)
10
+ nachos.execute
11
+ end
12
+
13
+ it "exits successfully" do
14
+ Nachos::CLI.stubs(:start)
15
+ nachos = Nachos.new
16
+ nachos.expects(:exit).with(0)
17
+ nachos.execute
18
+ end
19
+
20
+ it "can do help" do
21
+ begin
22
+ Nachos::CLI.any_instance.stubs(:shell).returns(shell = stub_everything())
23
+ Nachos.execute("help")
24
+ rescue SystemExit => e
25
+ end
26
+ end
27
+ end
28
+
4
29
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rob Sanheim
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-06 00:00:00 -04:00
17
+ date: 2010-08-13 00:00:00 -04:00
18
18
  default_executable: nachos
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -107,12 +107,13 @@ extensions: []
107
107
 
108
108
  extra_rdoc_files:
109
109
  - LICENSE
110
- - README.rdoc
110
+ - README.markdown
111
111
  files:
112
112
  - .document
113
113
  - .gitignore
114
+ - .rvmrc
114
115
  - LICENSE
115
- - README.rdoc
116
+ - README.markdown
116
117
  - Rakefile
117
118
  - bin/nachos
118
119
  - features/nachos.feature
@@ -121,12 +122,15 @@ files:
121
122
  - features/support/fakeweb/fakes.rb
122
123
  - lib/nachos.rb
123
124
  - lib/nachos/cli.rb
125
+ - lib/nachos/config.rb
124
126
  - lib/nachos/github.rb
125
127
  - lib/nachos/main.rb
126
128
  - lib/nachos/version.rb
127
129
  - nachos.gemspec
128
130
  - spec/nachos/cli_spec.rb
131
+ - spec/nachos/config_spec.rb
129
132
  - spec/nachos/github_spec.rb
133
+ - spec/nachos/main_spec.rb
130
134
  - spec/nachos_spec.rb
131
135
  - spec/spec_helper.rb
132
136
  has_rdoc: true
@@ -163,6 +167,8 @@ specification_version: 3
163
167
  summary: Nachos - sync and stuff with Github
164
168
  test_files:
165
169
  - spec/nachos/cli_spec.rb
170
+ - spec/nachos/config_spec.rb
166
171
  - spec/nachos/github_spec.rb
172
+ - spec/nachos/main_spec.rb
167
173
  - spec/nachos_spec.rb
168
174
  - spec/spec_helper.rb