Class: GithubMembers::CLI
- Inherits:
-
Object
- Object
- GithubMembers::CLI
- Defined in:
- lib/github_members/cli.rb
Defined Under Namespace
Classes: RequiredMemberAttributes
Constant Summary collapse
- EXIT_SUCCESS =
0- EXIT_FAILURE =
1
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
11 12 13 |
# File 'lib/github_members/cli.rb', line 11 def initialize(argv) @argv = argv end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
8 9 10 |
# File 'lib/github_members/cli.rb', line 8 def argv @argv end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/github_members/cli.rb', line 9 def @options end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/github_members/cli.rb', line 15 def run begin @options = Options.new(argv) rescue Options::ParseError => e warn e. return EXIT_FAILURE end case when .help_shown puts .help return EXIT_SUCCESS when .version puts .version return EXIT_SUCCESS when .github_org.nil? warn "Error: Organization is missing" warn "" warn .help return EXIT_FAILURE end org = Organization.new(client.fetch_organization(.github_org)) yaml_file = .yaml_file members = begin read_members(yaml_file) rescue RequiredMemberAttributes => e warn e. return EXIT_FAILURE end client.fetch_members(org.name).each do |new_member| github = new_member.fetch(:github) fullname = new_member.fetch(:fullname) avatar = new_member.fetch(:avatar) if members.key?(github) members[github].tap do |m| m.fullname = fullname m.avatar = avatar m.updated = true end else members[github] = member_class.new( github: github, fullname: fullname, avatar: avatar, updated: true ) end end members.delete_if { |_, m| !m.updated } write_members(members.values, yaml_file) puts "Updated: #{yaml_file}" markdown_file = .markdown_file MarkdownWriter.new.write(org: org, members: members.values, file: markdown_file) puts "Updated: #{markdown_file}" EXIT_SUCCESS end |