warp-dir 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.atom-build.json +22 -0
  3. data/.codeclimate.yml +22 -0
  4. data/.gitignore +40 -0
  5. data/.idea/encodings.xml +6 -0
  6. data/.idea/misc.xml +14 -0
  7. data/.idea/modules.xml +8 -0
  8. data/.idea/runConfigurations/All_Specs.xml +33 -0
  9. data/.idea/vcs.xml +6 -0
  10. data/.idea/warp-dir.iml +224 -0
  11. data/.rspec +4 -0
  12. data/.rubocop.yml +1156 -0
  13. data/.travis.yml +13 -0
  14. data/Gemfile +4 -0
  15. data/Guardfile +14 -0
  16. data/LICENSE +22 -0
  17. data/README.md +114 -0
  18. data/ROADMAP.md +96 -0
  19. data/Rakefile +24 -0
  20. data/bin/console +11 -0
  21. data/bin/setup +8 -0
  22. data/bin/warp-dir +13 -0
  23. data/bin/warp-dir.bash +25 -0
  24. data/lib/warp.rb +4 -0
  25. data/lib/warp/dir.rb +65 -0
  26. data/lib/warp/dir/app/cli.rb +162 -0
  27. data/lib/warp/dir/app/response.rb +133 -0
  28. data/lib/warp/dir/command.rb +120 -0
  29. data/lib/warp/dir/command/add.rb +16 -0
  30. data/lib/warp/dir/command/help.rb +80 -0
  31. data/lib/warp/dir/command/install.rb +78 -0
  32. data/lib/warp/dir/command/list.rb +13 -0
  33. data/lib/warp/dir/command/ls.rb +31 -0
  34. data/lib/warp/dir/command/remove.rb +16 -0
  35. data/lib/warp/dir/command/warp.rb +24 -0
  36. data/lib/warp/dir/commander.rb +71 -0
  37. data/lib/warp/dir/config.rb +87 -0
  38. data/lib/warp/dir/errors.rb +60 -0
  39. data/lib/warp/dir/formatter.rb +77 -0
  40. data/lib/warp/dir/point.rb +53 -0
  41. data/lib/warp/dir/serializer.rb +14 -0
  42. data/lib/warp/dir/serializer/base.rb +43 -0
  43. data/lib/warp/dir/serializer/dotfile.rb +36 -0
  44. data/lib/warp/dir/store.rb +129 -0
  45. data/lib/warp/dir/version.rb +6 -0
  46. data/spec/fixtures/warprc +2 -0
  47. data/spec/spec_helper.rb +71 -0
  48. data/spec/support/cli_expectations.rb +118 -0
  49. data/spec/warp/dir/app/cli_spec.rb +225 -0
  50. data/spec/warp/dir/app/response_spec.rb +131 -0
  51. data/spec/warp/dir/command_spec.rb +62 -0
  52. data/spec/warp/dir/commands/add_spec.rb +40 -0
  53. data/spec/warp/dir/commands/install_spec.rb +20 -0
  54. data/spec/warp/dir/commands/list_spec.rb +37 -0
  55. data/spec/warp/dir/config_spec.rb +45 -0
  56. data/spec/warp/dir/errors_spec.rb +16 -0
  57. data/spec/warp/dir/formatter_spec.rb +38 -0
  58. data/spec/warp/dir/point_spec.rb +35 -0
  59. data/spec/warp/dir/store_spec.rb +105 -0
  60. data/warp-dir.gemspec +56 -0
  61. metadata +228 -0
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ env:
3
+ - CODECLIMATE_REPO_TOKEN=5306e7c3069bd3fef06f717d679f41e969e13bb05efef5bbe1fd781043b0c117
4
+ rvm:
5
+ - 2.2.3
6
+ - 2.3.0
7
+ script: "bundle exec rspec"
8
+ notifications:
9
+ email:
10
+ recipients:
11
+ - kigster@gmail.com
12
+ on_success: never
13
+ on_failure: always
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in warp-dir.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ #^syntax detection
3
+
4
+ # A sample Guardfile
5
+ # More info at https://github.com/guard/guard#readme
6
+
7
+ guard 'rspec' do
8
+ watch(%r{^warp-dir\.gemspec}) { "spec"}
9
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch('spec/spec_helper.rb') { "spec" }
12
+ watch(%r{spec/support/.*}) { "spec" }
13
+ end
14
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Konstantin Gredeskoul
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Warp Directory
2
+
3
+ [![Build Status](https://travis-ci.org/kigster/warp-dir.svg?branch=master)](https://travis-ci.org/kigster/warp-dir)
4
+ [![Code Climate](https://codeclimate.com/github/kigster/warp-dir/badges/gpa.svg)](https://codeclimate.com/github/kigster/warp-dir)
5
+ [![Test Coverage](https://codeclimate.com/github/kigster/warp-dir/badges/coverage.svg)](https://codeclimate.com/github/kigster/warp-dir/coverage)
6
+ [![Issue Count](https://codeclimate.com/github/kigster/warp-dir/badges/issue_count.svg)](https://codeclimate.com/github/kigster/warp-dir)
7
+
8
+ <hr/>
9
+ [![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/kigster/warp-dir)
10
+ <hr/>
11
+
12
+ This is a ruby implementation of the tool 'wd' (warp directory),
13
+ [originally written as a zsh module](https://github.com/mfaerevaag/wd)
14
+ by [Markus Færevaag](https://github.com/mfaerevaag).
15
+
16
+ After finding it very useful, but having to switch to `bash` on occasion, I wanted to have a completely
17
+ compatible tool that is well tested, and can be extended to do some more interesting things.
18
+
19
+ Markus kindly offered a ruby version in a [separate branch of this module](https://github.com/mfaerevaag/wd/tree/ruby),
20
+ which served as an inspiration for this gem.
21
+
22
+ The overall concept comes from the realization that when we work on the command line, we
23
+
24
+ * often have to deal with a limited number of folders at any given time
25
+ * it would be nice to quickly switch between these folders (which we call __warp points__).
26
+ * it should be easy to add, remove, list, and validate warp points
27
+ * everything should require as few characters as possible :)
28
+
29
+ Some future extensions could be based on some additional realizations:
30
+
31
+ * each folder often represents a project, some of which are managed by `git`
32
+ * eventually we might want to do things across all projects, such as perform group `git pull`,
33
+ or even `git push` etc.
34
+
35
+ ## Installation
36
+
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'warp-dir', '~> 1.0 '
41
+ ```
42
+ And then execute:
43
+
44
+ $ bundle
45
+
46
+ Or install it yourself as:
47
+
48
+ $ gem install warp-dir --no-ri --no-rdoc
49
+
50
+ After the installation, you will have the `warp-dir` command in the path,
51
+ which actually returns (as it's output) commands for the shell to
52
+ interprete. This is why you also need to install a tiny shell function
53
+ to wrap this gem's executable.
54
+
55
+ You can do it using several ways:
56
+
57
+ $ warp-dir install [ --file <file> ]
58
+
59
+ This command will ensure you have the wrapper installed in your ~/.bashrc or ~/.zshrc.
60
+ Without the `--file` option, it will install it in both if it finds them. With the
61
+ `--file` option, it will only add the shell function to the file specified.
62
+
63
+ And after that you should be able to get the helpful message below by typing:
64
+
65
+ $ wd help
66
+
67
+ If the above command returns a properly formatted help like the image below, your setup
68
+ is now complete!
69
+
70
+ ## Usage
71
+
72
+ The usage of the tool is a derived superset of the `ZSH`-based inspiration.
73
+
74
+ ![Image](doc/wd-help-800x710.png)
75
+
76
+ #### Notable Differences
77
+
78
+ * instead of `wd add!` use `wd add -f <point>` (or --force)
79
+ * for now `wd clean` is not supported.
80
+
81
+ ## Future Development
82
+
83
+ I have so many cool ideas about where this can go, that I created a
84
+ [dedicated page](ROADMAP.md) for the discussion of future features. Please head over
85
+ there if you'ld like to participate.
86
+
87
+ ## Development
88
+
89
+ After checking out the repo, run `bin/setup` to install dependencies.
90
+ You can also run `bin/console` for an interactive prompt that will
91
+ allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`.
94
+ To release a new version, update the version number in `version.rb`, and
95
+ then run `bundle exec rake release`, which will create a git tag for the
96
+ version, push git commits and tags, and push the `.gem` file
97
+ to [rubygems.org](https://rubygems.org).
98
+
99
+ ## Adding New Commands
100
+
101
+ Just follow the patter in the `lib/warp/dir/commands/` folder, copy and modify
102
+ one of the existing commands. Command class name is used as an actual command.
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/warp-dir.
107
+
108
+ ## Author
109
+
110
+ <p>&copy; 2016 Konstantin Gredeskoul, all rights reserved.</p>
111
+
112
+ ## License
113
+
114
+ This project is distributed under the [MIT License](https://raw.githubusercontent.com/kigster/warp-dir/master/LICENSE).
data/ROADMAP.md ADDED
@@ -0,0 +1,96 @@
1
+ # Warp Directory – Future Roadmap
2
+
3
+ [![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/kigster/warp-dir)
4
+
5
+ Here I'd like to document various ideas and feature requests from myself and others.
6
+
7
+ ## Simplify Interface
8
+
9
+ Questionable value, but this sort of interface appear a bit more consistent.
10
+
11
+ Still I am not sure I want to type `wd -j proj` or `wd -a proj` instead of `wd proj` and `wd add proj`...
12
+
13
+ ```bash
14
+ wd -j/--jump point
15
+ wd -a/--add point
16
+ wd -r/--remove point
17
+ wd -l/--ls point
18
+ wd -p/--path point
19
+
20
+ wd -L/--list
21
+ wd -C/--clean
22
+ wd -S/--scan # report whether points exist on the file system
23
+ ```
24
+
25
+ ## Run Commands In A Warp Point
26
+
27
+ Pass an arbitrary command to execute, and return back to CWD.
28
+
29
+ ```bash
30
+ wd proj -x/--exec -- "command"
31
+ ```
32
+
33
+ ## Group Commands
34
+
35
+ Create a group of several warp points:
36
+
37
+ ```bash
38
+ wd -g/--group group1 -d/--define "point1,point2,...,pointN"
39
+ wd -g/--group group1 -r/--remove point1 # remove a point from the group
40
+ wd -g/--group group1 -a/--add point1 # add a point to the group
41
+ ```
42
+
43
+ Execute command in all warp points of the group:
44
+
45
+ ```bash
46
+ wd -x/--exec [ -g/--group group ] [ -r/--return-code ] -- command
47
+ ```
48
+
49
+ As above, until one returns non-blank output (ie, search).
50
+ If -r is passed, it stops at the first return code of value passed, or 0
51
+
52
+ ```bash
53
+ wd -f/--find [ -g/--group group ] [ -r/--return-code ] -- command
54
+ ```
55
+
56
+ As above, until one returns blank output. If -r is passed, it stops at the first
57
+ return code not equal to the value passed, or 0
58
+
59
+ ```bash
60
+ wd -a/--all [ -g/--group group ] [ -r/--return-code ] -- command
61
+
62
+ ```
63
+
64
+ The idea here is that you can group several warp points together, and then
65
+ execute a command in all of them. You could use to:
66
+
67
+ * search for a specific file in one of the project repos – you expect to exist in
68
+ only one of them, and so you want the search to stop once found (indicated
69
+ by return code equal to 1):
70
+
71
+ ```bash
72
+ wd --find --group project-group --return-code=1 -- \
73
+ find . -name .aws-credentials.lol
74
+ ```
75
+
76
+ * you want to run rspec in all projects of the group, and stop at the
77
+ first non-zero return:
78
+
79
+ ```bash
80
+ wd --all --group project-group --return-code -- bundle exec rspec
81
+ ```
82
+
83
+ ## Networking
84
+
85
+ Can we go across SSH?
86
+
87
+ ```bash
88
+ wd add proj kig@remote.server.com:~/workspace/proj
89
+ wd ls proj
90
+ wd proj
91
+ ```
92
+ This then establishes and SSH connection to the server and logs you into the shell. Should be pretty easy, I think :)
93
+
94
+ ## What Else?
95
+
96
+ Sky is the limit :) Well, and the black hole that the warp directory is :)
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ task :default => [:rspec ]
2
+
3
+ task :install do
4
+ [
5
+ %q(chmod -R o+r .),
6
+ %q(rm -f *.gem),
7
+ %q(rm -rf build),
8
+ %q(gem uninstall -a --executables warp-dir 2> /dev/null; true),
9
+ %q(gem build warp-dir.gemspec)
10
+ ].each do |command|
11
+ sh command
12
+ end
13
+ sh <<-EOF
14
+ export gem_file=$(ls -1 *.gem | tail -1)
15
+ export gem_name=${gem_file//.gem/}
16
+ gem install $gem_file --no-wrappers --force --quiet
17
+ EOF
18
+ exit 0
19
+ end
20
+
21
+ require 'bundler'
22
+ require "bundler/gem_tasks"
23
+ require 'rake/clean'
24
+ require 'rspec/core/rake_task'
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "warp/dir"
5
+
6
+ # (If you use this, don't forget to add pry to your Gemfile!)
7
+ # require "pry"
8
+ # Pry.start
9
+
10
+ require "irb"
11
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/warp-dir ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+
5
+ lib_path = File.dirname(__FILE__) + '/../lib'
6
+ if File.exist?(lib_path)
7
+ $LOAD_PATH << lib_path
8
+ require 'warp/dir'
9
+ require 'warp/dir/app/cli'
10
+ end
11
+
12
+ response = Warp::Dir::App::CLI.new(ARGV.dup).run
13
+ response.print.exit! if response
data/bin/warp-dir.bash ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # warp-dir shell wrapper
4
+ wd() {
5
+ if [ -z "${warp_dir_exec_installed}" ]; then
6
+ $(which 'warp-dir') 2>&1 > /dev/null
7
+ export warp_dir_exec_installed=$?
8
+ fi
9
+
10
+ if [ ${warp_dir_exec_installed} -eq 0 ]; then
11
+ IFS_BACKUP=$IFS
12
+ IFS="+"
13
+ output=$(WARP_DIR_SHELL=yes warp-dir $@ 2>&1)
14
+ code=$?
15
+ eval ${output}
16
+ IFS=$IFS_BACKUP
17
+ else
18
+ printf "\nWhoops – I can't find 'warp-dir' executable.\n"
19
+ printf "Is the gem properly installed?\n"
20
+ printf "\nTry reinstalling the gem with, for example:\n\n"
21
+ printf " $ gem install warp-dir --no-wrappers\n"
22
+ printf " $ hash -r\n"
23
+ printf " $ warp-dir install [ --dotfile ~/.bashrc ]\n"
24
+ fi
25
+ }
data/lib/warp.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'warp/dir'
2
+ module Warp
3
+
4
+ end
data/lib/warp/dir.rb ADDED
@@ -0,0 +1,65 @@
1
+ module Warp
2
+ PROJECT_LIBS = File.dirname(File.absolute_path(__FILE__))
3
+ PROJECT_HOME = PROJECT_LIBS + '/../..'
4
+
5
+ module Dir
6
+ DOTFILES = %w(~/.bashrc ~/.zshrc ~/.profile)
7
+ SHELL_WRAPPER = "#{PROJECT_HOME}/bin/warp-dir.bash"
8
+
9
+ class << self
10
+ def require_all_from(folder)
11
+ ::Dir.glob(Warp::PROJECT_LIBS + folder + '/*.rb') { |file| Kernel.require file }
12
+ end
13
+
14
+ def eval_context?
15
+ ENV['WARP_DIR_SHELL'] == 'yes'
16
+ end
17
+
18
+ def pwd
19
+ %x(pwd).chomp.gsub ENV['HOME'], '~'
20
+ end
21
+
22
+ def relative(path)
23
+ path.gsub ENV['HOME'], '~'
24
+ end
25
+
26
+ def absolute(path)
27
+ path.gsub '~', ENV['HOME']
28
+ end
29
+
30
+ def default_config
31
+ relative Warp::Dir::Config::DEFAULTS[:warprc]
32
+ end
33
+
34
+ def sort_by(collection, field)
35
+ collection.sort { |a, b| a.send(field) <=> b.send(field) }
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
42
+ Warp::Dir.require_all_from '/dir'
43
+ Warp::Dir.require_all_from '/dir/command'
44
+
45
+ module Warp
46
+ module Dir
47
+ class << self
48
+ def on(type, &block)
49
+ Warp::Dir::App::Response.new.type(type).configure(&block)
50
+ end
51
+
52
+ def commander
53
+ ::Warp::Dir::Commander.instance
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ class Object
61
+ def blank?
62
+ self.eql?('') || self.nil?
63
+ end
64
+ end
65
+
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'warp/dir'
4
+ require 'slop'
5
+ require 'colored'
6
+
7
+ module Warp
8
+ module Dir
9
+ module App
10
+ class CLI
11
+ attr_accessor :argv, :config, :commander, :store, :validated, :opts, :flags
12
+
13
+ def initialize(argv)
14
+ self.argv = argv
15
+
16
+ # flags are everything that follows -- and is typically flags for the command.
17
+ # for example: 'wd ls project-point -- -alF' would extract flags = [ '-alF' ]
18
+ self.flags = extract_suffix_flags(argv.dup)
19
+ self.flags.flatten!
20
+ self.commander = ::Warp::Dir::Commander.instance
21
+ self.config = ::Warp::Dir::Config.new
22
+ self.opts = nil
23
+ end
24
+
25
+ def validate
26
+ self.validated = false
27
+ no_arguments = argv.empty?
28
+ commands = shift_non_flag_commands
29
+ self.opts = parse_with_slop(self.argv)
30
+ # merge first few non-flag args which we filtered into `commands` hash
31
+ # merge onto the hash resulting from options
32
+ # and pass on to override the default config opts for the final config.
33
+ config.configure(opts.to_hash.merge(commands))
34
+
35
+ self.store = Warp::Dir::Store.new(config, Warp::Dir::Serializer::Dotfile)
36
+
37
+ config.command = :help if (opts.help? || no_arguments)
38
+ config.command = :warp if !config.command && config.warp
39
+
40
+ if config[:command]
41
+ self.validated = true
42
+ else
43
+ raise Warp::Dir::Errors::InvalidCommand.new('Unable to determine what command to run.'.red)
44
+ end
45
+ yield self if block_given?
46
+ validated
47
+ end
48
+
49
+ def run(&block)
50
+ validate unless validated?
51
+ response = process_command
52
+ yield response if block_given?
53
+ response
54
+ rescue Exception => e
55
+ if config.debug
56
+ STDERR.puts(e.inspect)
57
+ STDERR.puts(e.backtrace.join("\n"))
58
+ end
59
+ on :error do
60
+ message e.message.red
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def on(*args, &block)
67
+ response = Warp::Dir.on(*args, &block)
68
+ response.config = self.config
69
+ response
70
+ end
71
+
72
+ def process_command
73
+ argv = self.argv
74
+ if config.command
75
+ command_class = commander.find(config.command)
76
+ if command_class
77
+ command_class.new(store, config.point).run(opts, *flags)
78
+ else
79
+ on :error do
80
+ message "command '#{config.command}' was not found.".red
81
+ end
82
+ end
83
+ else
84
+ on :error do
85
+ message "#{$0}: passing #{argv ? argv.join(', ') : 'no arguments'} is invalid.".red
86
+ end
87
+ end
88
+ end
89
+
90
+ def parse_with_slop(arguments)
91
+ opts = Slop::Options.new
92
+ opts.banner = nil
93
+ opts.string '-m', '--command', '<command> – command to run, ie. add, ls, list, rm, etc.'
94
+ opts.string '-p', '--point', '<point-name> – name of the warp point'
95
+ opts.string '-w', '--warp', '<warp-point> – warp to a given point'
96
+ opts.bool '-f', '--force', ' - force, ie. overwrite existing point when adding'
97
+ opts.bool '-h', '--help', ' – show help'
98
+ opts.bool '-v', '--verbose', ' – enable verbose mode'
99
+ opts.bool '-q', '--quiet', ' – suppress output (quiet mode)'
100
+ opts.bool '-d', '--debug', ' – show stacktrace if errors are detected'
101
+ opts.string '-s', '--dotfile', '<dotfile> – shell init file to append the wd wrapper, eg. ~/.bashrc'
102
+ opts.string '-c', '--config', '<config> – location of the configuration file (default: ' + Warp::Dir.default_config + ')', default: Warp::Dir.default_config
103
+ opts.on '-V', '--version', ' – print the version' do
104
+ puts 'Version ' + Warp::Dir::VERSION
105
+ exit
106
+ end
107
+
108
+ Slop::Parser.new(opts).parse(arguments)
109
+ end
110
+
111
+ # Given args of the form:
112
+ # [ 'ls' 'project' --verbose --debug -- -alF ]
113
+ # this returns:
114
+ # {
115
+ # command: :ls,
116
+ # point: :project
117
+ # }
118
+ def shift_non_flag_commands
119
+ result = {}
120
+ non_flags = []
121
+ non_flags << argv.shift while not_a_flag(argv.first)
122
+ case non_flags.size
123
+ when 1
124
+ argument = non_flags.first.to_sym
125
+ if commander.lookup(argument)
126
+ result[:command] = argument
127
+ else
128
+ result[:command] = :warp
129
+ result[:point] = argument
130
+ end
131
+ when 2
132
+ result[:command], result[:point] = non_flags.map(&:to_sym)
133
+ when 3
134
+ #
135
+ # This is for the hypothetical but awesome future:
136
+ #
137
+ # wd add proj_remote kig@remote.server.com:~/workspace/proj
138
+ # wd proj_remote
139
+ #
140
+ # >>>>.... ssh kig@remote.server.com -c "cd ~/workspace/proj"
141
+ #
142
+ result[:command], result[:point], result[:point_path] = non_flags.map(&:to_sym)
143
+ end
144
+ result
145
+ end
146
+
147
+ def extract_suffix_flags(list)
148
+ element = list.shift until element.eql?('--') || list.empty?
149
+ list
150
+ end
151
+
152
+ def validated?
153
+ self.validated
154
+ end
155
+
156
+ def not_a_flag(arg)
157
+ arg && !arg[0].eql?('-')
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end