smdev 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smdev.rb +87 -81
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ee5c9e422aae48b90084d189278e78c33178f57948ce6ef99635e9d6ecad21f
4
- data.tar.gz: 8935b9ce2448eac97832cb02f9321b70e46f6b7a7913b58c3e7dfce28d530f18
3
+ metadata.gz: 74b463faf28bf0f34c9bfc7ab00726862bf4763bcb70ca3ebe7f77d6673f2052
4
+ data.tar.gz: ae57a1b92b6686b953867d803f3f213db31b970275587541ef19c735c2e1bb3b
5
5
  SHA512:
6
- metadata.gz: 1df56102c08ba43782f61a10a9d868ae8ead1d3c792ef4c898dd16641c1248b0c5144ef316558ff35875e319144a933d4bec6e47e7d29704e898d47b71ada80d
7
- data.tar.gz: 0a1672ee3c0bd427711ee208b92a0e690cc0579ea5845056df97af0b7c99964e412ab0578440089abd7713487ea21a876a8a1383e69981848349dd67fe193ff1
6
+ metadata.gz: b1a91f538de100ccdfcf5601d448107a8afd027ed774d62b0404b72e907eeaacb052b6e56eea11c3a028f36ea2fef68683dc20fa09afd358e8c96836ee5665f2
7
+ data.tar.gz: 2907d1be5ad5c1fea1d3b0a404ba4ef6f4d198b3045c3ac232a1d84d1efc3332d79afa01fe100e59eb7cf03f894f142d9c7f88f474e20df18ad45aac85f156e8
data/lib/smdev.rb CHANGED
@@ -5,10 +5,14 @@ require 'optparse'
5
5
 
6
6
  module Smdev
7
7
  class CLI
8
- def run
8
+ def run(args = ARGV)
9
9
  options = {}
10
+ commands = ["local_app_setup : Install local requirements for application. (Rails Only Currently)\n",
11
+ "system_install : Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails\n",
12
+ "checkout_repos : Checkout all repositories for StrongMind\n"]
13
+
10
14
  OptionParser.new do |opts|
11
- opts.banner = "Usage: smdev.rb [options]"
15
+ opts.banner = "Usage: smdev.rb [options] <command>"
12
16
 
13
17
  opts.on("-t", "--team TEAM_NAME", "Pull repositories assigned to a specific team") do |team_name|
14
18
  options[:team] = team_name
@@ -20,35 +24,14 @@ module Smdev
20
24
 
21
25
  opts.on("-h", "--help", "Prints this help message") do
22
26
  puts opts
27
+ puts "\nCommands:"
28
+ commands.each { |cmd| puts " #{cmd}" }
23
29
  exit
24
30
  end
25
31
 
26
- opts.on("-l", "--local-app-install", "Setup this local application") do
27
- options[:local_install] = true
28
- end
29
-
30
- opts.on("-i", "--install", "Install Homebrew, Ruby, PostgreSQL, and Ruby on Rails") do
31
- options[:install] = true
32
- end
33
32
  end.parse!
34
33
 
35
- if options[:local_install]
36
- puts "Running Bundle Install"
37
- system('bundle', 'install')
38
-
39
- puts "Copying env file"
40
- system('cp', '.env.example', '.env')
41
-
42
- puts "Create database"
43
- system('bin/rails', 'db:create')
44
-
45
- puts "Run database migrations"
46
- system('rails', 'db:migrate')
47
-
48
- end
49
-
50
- if options[:install]
51
- # Install Homebrew
34
+ def system_install
52
35
  puts "Installing Homebrew..."
53
36
  system({ 'SHELL' => '/bin/bash' }, '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"')
54
37
  # system('/bin/bash', '-c', "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)")
@@ -105,68 +88,91 @@ module Smdev
105
88
  # Install Ruby on Rails
106
89
  puts "Installing Ruby on Rails..."
107
90
  system('sudo', 'gem', 'install', 'rails')
108
-
109
- # If install option is provided, exit the script
110
- exit if options[:install]
111
91
  end
112
-
113
- token = ENV['GITHUB_TOKEN']
114
- if token.nil?
115
- # Prompt the user for their GitHub personal access token
116
- print "GitHub personal access token: "
117
- token = STDIN.noecho(&:gets).chomp
118
- puts ""
119
- end
120
- # Authenticate with the GitHub API using the user's credentials
121
- client = Octokit::Client.new(access_token: token)
122
-
123
- # Specify the organization name
124
- org_name = "StrongMind"
125
-
126
- if options[:team]
127
- # A team name was provided as a command-line argument
128
- team_name = options[:team]
129
- # Get a list of all teams in the organization
130
- teams = client.organization_teams(org_name)
131
- # Find the team with the specified name
132
- team = teams.find { |t| t.name == team_name }
133
- if team.nil?
134
- puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
135
- exit
92
+ def checkout_repos(options)
93
+ token = ENV['GITHUB_TOKEN']
94
+ if token.nil?
95
+ # Prompt the user for their GitHub personal access token
96
+ print "GitHub personal access token: "
97
+ token = STDIN.noecho(&:gets).chomp
98
+ puts ""
136
99
  end
137
- # Get a list of all repositories in the organization that are assigned to the specified team
138
- #
139
- repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
140
- puts "Team Name #{team_name} - Team ID: #{team.id}"
141
- else
142
- repos = []
143
- page_number = 1
144
- per_page = 100
145
- loop do
146
- repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
147
- repos.concat(repos_page)
148
- break if repos_page.length < per_page
149
- page_number += 1
100
+ # Authenticate with the GitHub API using the user's credentials
101
+ client = Octokit::Client.new(access_token: token)
102
+
103
+ # Specify the organization name
104
+ org_name = "StrongMind"
105
+
106
+ if options[:team]
107
+ # A team name was provided as a command-line argument
108
+ team_name = options[:team]
109
+ # Get a list of all teams in the organization
110
+ teams = client.organization_teams(org_name)
111
+ # Find the team with the specified name
112
+ team = teams.find { |t| t.name == team_name }
113
+ if team.nil?
114
+ puts "Error: Could not find team with name '#{team_name}' in organization '#{org_name}'"
115
+ exit
116
+ end
117
+ # Get a list of all repositories in the organization that are assigned to the specified team
118
+ #
119
+ repos = client.org_repos(org_name, { :affiliation => 'organization_member', :team_id => team.id })
120
+ puts "Team Name #{team_name} - Team ID: #{team.id}"
121
+ else
122
+ repos = []
123
+ page_number = 1
124
+ per_page = 100
125
+ loop do
126
+ repos_page = client.organization_repositories(org_name, { :affiliation => 'owner,organization_member', :per_page => per_page, :page => page_number })
127
+ repos.concat(repos_page)
128
+ break if repos_page.length < per_page
129
+ page_number += 1
130
+ end
131
+
132
+ # # No team name was provided, so get a list of all teams in the organization
133
+ # teams = client.organization_teams(org_name)
134
+ # # Get a list of all repositories in the organization that are assigned to each team
135
+ # repos = []
136
+ # teams.each do |team|
137
+ # team_repos = client.team_repos(team.id)
138
+ # repos.concat(team_repos)
139
+ # end
140
+ end
141
+
142
+ # Clone each repository to a local directory
143
+ repos.each do |repo|
144
+ clone_url = repo.clone_url
145
+ ssh_url = repo.ssh_url
146
+ repo_name = repo.name
147
+ url = options[:https] ? clone_url : ssh_url
148
+ `git clone #{url} #{repo_name}`
150
149
  end
151
150
 
152
- # # No team name was provided, so get a list of all teams in the organization
153
- # teams = client.organization_teams(org_name)
154
- # # Get a list of all repositories in the organization that are assigned to each team
155
- # repos = []
156
- # teams.each do |team|
157
- # team_repos = client.team_repos(team.id)
158
- # repos.concat(team_repos)
159
- # end
160
151
  end
161
152
 
162
- # Clone each repository to a local directory
163
- repos.each do |repo|
164
- clone_url = repo.clone_url
165
- ssh_url = repo.ssh_url
166
- repo_name = repo.name
167
- url = options[:https] ? clone_url : ssh_url
168
- `git clone #{url} #{repo_name}`
153
+ command = args.shift
154
+
155
+ case command
156
+ when "local_app_setup"
157
+ puts "Running Bundle Install"
158
+ system('bundle', 'install')
159
+
160
+ puts "Copying env file"
161
+ system('cp', '.env.example', '.env')
162
+
163
+ puts "Create database"
164
+ system('bin/rails', 'db:create')
165
+
166
+ puts "Run database migrations"
167
+ system('rails', 'db:migrate')
168
+ when "system_install"
169
+ system_install(options)
170
+ when "checkout_repos"
171
+ checkout_repos(options)
172
+ else
173
+ puts "Invalid command: #{command}. Use --help for a list of commands."
169
174
  end
175
+
170
176
  end
171
177
  end
172
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smdev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Neighbors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-01 00:00:00.000000000 Z
11
+ date: 2023-09-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: StrongMind Development Tool
14
14
  email: derek.neighbors@strongmind.com