Class: DevFlow::Init
Instance Attribute Summary
Attributes inherited from App
#command, #config, #git, #logger, #members, #roadmap, #waiting
Instance Method Summary collapse
Methods inherited from App
#all_member_names, #ask_rebase, #debug, #display_close_waiting, #display_tasks, #error, #hello, #hr, #hrb, #hrbh, #hrh, #i_am_leader?, #i_am_moderator?, #i_am_supervisor?, #i_have_power?, #in_release?, #in_trunk?, #info, #initialize, #leader_name, #load_roadmap, #new_version, #switch_to!, #sync?, #task, #tasks_for_close, #upload_progress!, #user_name, #warn
Constructor Details
This class inherits a constructor from DevFlow::App
Instance Method Details
#add_to_gitignore ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/dev_flow/commands/init.rb', line 69 def add_to_gitignore had = false if File.exists?(".gitignore") fh = File.open(".gitignore") fh.each do |line| had = true if line =~ /#{@config[:local_config]}/ end fh.close end unless had info "add local configuration file to gitignore list" wh = File.open(".gitignore", 'a') wh.puts @config[:local_config] wh.close end end |
#process! ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 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 |
# File 'lib/dev_flow/commands/init.rb', line 4 def process! local_configuration = {} if File.exists? @config[:local_config] local_configuration = YAML.load(File.open(@config[:local_config], 'r:utf-8').read) || {} end # find the current user sugguest = @config["whoami"] if @config["whoami"] unless @roadmap.team_member_names.include? sugguest info "use system 'whoami' command to find user name" begin suggest = `whoami` end info "found #{suggest}" if @roadmap.team_member_names.include? sugguest end unless @roadmap.team_member_names.include? sugguest info "use git config to find user name" sugguest = @git.config["user.email"].gsub(/\@.+$/, '') if @git.config["user.email"] info "found #{suggest}" if @roadmap.team_member_names.include? sugguest end # ask the user for the user name puts "Tell us who you are: ".bold.yellow msg = @roadmap.team_member_names.join(", ") if @roadmap.team_member_names.include? sugguest msg += " [#{sugguest}]" end print msg + ":" ans = STDIN.gets.chomp! ans = sugguest unless ans.size > 0 error "Unknown member! Can not continue." unless all_member_names.include? ans error "You are not in the team, you should not edit the files under this project." unless @roadmap.team_member_names.include? ans # find the default git remote server @config["whoami"] = ans info "Welcome #{self.user_name.bold}!" remotes = @git.remote_list error "You need to set at least one remote git server to interact with!" unless remotes.size > 0 puts "Which remote git server to use?".bold.yellow msg = remotes.join ", " suggest = @config["git_remote"] || 'origin' msg += " [#{suggest}]" if remotes.include? suggest print msg + ":" ans2 = STDIN.gets.chomp! ans2 = suggest unless ans2.size > 0 error "You must define a valid git remote server." unless remotes.include? ans2 # write out to the local configuration file info "write contents to local configuration file" write_local_config(local_configuration.merge({"whoami" => ans, "git_remote" => ans2})) add_to_gitignore() end |
#write_local_config(hash) ⇒ Object
63 64 65 66 67 |
# File 'lib/dev_flow/commands/init.rb', line 63 def write_local_config hash wh = File.open(@config[:local_config], 'w:utf-8') YAML.dump(hash, wh) wh.close end |