Sha256: 5b15b1ad6f231111916696608f5d6a9b62981b86238033a5d93ac46874d5320e

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

#!/usr/bin/env ruby

require 'shellject'
require 'clamp'

Clamp do

  option ['--save-dir', '-s'], 'DIRECTORY',
    'The directory in which to store encrypted shelljections.',
    environment_variable: 'SHELLJECT_SAVE_DIR',
    default: '~/.shellject/shelljections',
    attribute_name: 'save_dir_path'

  option ['--version', '-v'], :flag, 'Show version' do
    puts Shellject::VERSION
    exit(0)
  end

  def save_directory
    Shellject::SaveDirectory.new(File.expand_path save_dir_path)
  end

  def with_error_handling
    yield
  rescue Shellject::ShelljectError => ex
    STDERR.puts "ERROR: #{ex.message}"
    STDERR.puts help
    exit(1)
  end

  subcommand 'save', 'Save the specified file as a shelljection' do
    option ['--name', '-n'], 'NAME',
      'What to name the shelljection. If not specified, the basename of the file will be used.'
    parameter 'INPUT_FILE', 'File to save', :attribute_name => :input_file
    def execute
      with_error_handling do
        Shellject::Tasks::Save.new(save_directory, input_file, name).call
      end
    end
  end

  subcommand 'load', 'Load the specified shelljection' do
    parameter 'NAME',
      'Name of the shelljection to load', :attribute_name => :name
    def execute
      with_error_handling do
        Shellject::Tasks::Load.new(save_directory, name).call
      end
    end
  end

  subcommand 'setup', 'Setup wrapper and completion' do
    def execute

      bash_dir = Pathname.new File.expand_path('../bash', __dir__)
      puts <<-eos
# You'll need to source the bash wrapper in order for values to be injected
# into your shell.
# Add the following line to your ~/.bash_profile or ~/.bashrc

source #{bash_dir.join 'shellject_wrapper.sh'}

# To add command line completion, add the following line to your ~/.bash_profile or ~/.bashrc

source #{bash_dir.join 'shellject_completion.sh'}

      eos
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shellject-1.0.2 exe/shellject
shellject-1.0.1 exe/shellject
shellject-0.3.0 exe/shellject
shellject-0.2.0 exe/shellject
shellject-0.1.0 exe/shellject