From e6cd38aa3572e57bce8f956f42c09e985d1643e7 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Sun, 7 May 2017 21:15:39 -0700 Subject: [PATCH] initial menu setup --- Gemfile | 3 +++ Gemfile.lock | 22 ++++++++++++++++++++++ bin/dots.rb | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/Gemfile b/Gemfile index 4c44d2f..464c756 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,9 @@ group :development, :unit_tests do gem 'puppetlabs_spec_helper', '~> 1.1' gem 'rspec-puppet', '~> 2.5' gem 'rubocop', '~> 0.48' + gem 'tty-command', '~> 0.4' + gem 'tty-file', '~> 0.3' + gem 'tty-prompt', '~> 0.12' gem 'yamllint', '~> 0.0.9' # puppet-lint and plugins diff --git a/Gemfile.lock b/Gemfile.lock index d7ae886..27c69a5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,7 @@ GEM cri (2.6.1) colored (~> 1.2) diff-lcs (1.3) + equatable (0.5.0) facter (2.4.6) facter (2.4.6-universal-darwin) CFPropertyList (~> 2.2.6) @@ -37,9 +38,13 @@ GEM metaclass (~> 0.0.1) multi_json (1.12.1) multipart-post (2.0.0) + necromancer (0.4.0) os (1.0.0) parser (2.4.0.0) ast (~> 2.2) + pastel (0.7.1) + equatable (~> 0.5.0) + tty-color (~> 0.4.0) powerpack (0.1.1) puppet (4.5.3) facter (> 2.0, < 4) @@ -125,7 +130,21 @@ GEM spdx-licenses (1.1.0) text (1.3.1) trollop (2.1.2) + tty-color (0.4.2) + tty-command (0.4.0) + pastel (~> 0.7.0) + tty-cursor (0.4.0) + tty-file (0.3.0) + diff-lcs (~> 1.3.0) + pastel (~> 0.7.0) + tty-prompt (~> 0.12.0) + tty-prompt (0.12.0) + necromancer (~> 0.4.0) + pastel (~> 0.7.0) + tty-cursor (~> 0.4.0) + wisper (~> 1.6.1) unicode-display_width (1.2.1) + wisper (1.6.1) yamllint (0.0.9) trollop (~> 2) @@ -156,6 +175,9 @@ DEPENDENCIES rspec-puppet (~> 2.5) rubocop (~> 0.48) rugged (~> 0.24) + tty-command (~> 0.4) + tty-file (~> 0.3) + tty-prompt (~> 0.12) yamllint (~> 0.0.9) BUNDLED WITH diff --git a/bin/dots.rb b/bin/dots.rb index 0c847fa..d250a81 100755 --- a/bin/dots.rb +++ b/bin/dots.rb @@ -1,5 +1,10 @@ require 'open3' require 'os' +require 'tty-command' +require 'tty-file' +require 'tty-prompt' + +prompt = TTY::Prompt.new(help_color: :magenta) if OS.mac? stdout, _stderr, _status = Open3.capture3('sw_vers -productVersion') @@ -22,3 +27,36 @@ elsif OS.windows? else abort("I'm not sure what to do with this OS...") end + +@home = File.expand_path('~') +@dotroot = File.dirname(File.dirname(File.expand_path($PROGRAM_NAME))) + +task = prompt.select('What would you like to do?', %w[copy link]) +case task +when 'copy' + files = Dir.glob("#{@dotroot}/copy/*") + + puts 'The following symlinks will be made:' + files.each do |file| + puts "#{@home}/.#{File.basename(file)} -> #{file}" + end + + if prompt.yes?('Shall we continue?') + puts 'yes' + else + puts 'no' + end +when 'link' + files = Dir.glob("#{@dotroot}/link/*") + + puts 'The following symlinks will be made:' + files.each do |file| + puts "#{@home}/.#{File.basename(file)} -> #{file}" + end + + if prompt.yes?('Shall we continue?') + puts 'yes' + else + puts 'no' + end +end