Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
Switched to Optimist. (#145)
Browse files Browse the repository at this point in the history
* Trollop is deprecated.
  • Loading branch information
davehewitt authored and jrgarcia committed Oct 9, 2018
1 parent 8671e1f commit a586755
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 99 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ A few important points:
* Data object types can usually be inferred from context, so you may use a hash instead.
* Enumeration values are simply strings.
* Example code is included in the examples/ directory.
* A set of helper methods for Trollop is included to speed up development of
* A set of helper methods for Optimist is included to speed up development of
command line apps. See the included examples for usage.
* If you don't have trusted SSL certificates installed on the host you're
connecting to, you'll get an `OpenSSL::SSL::SSLError` "certificate verify
Expand Down
14 changes: 7 additions & 7 deletions examples/annotate.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM
CMDS = %w(get set)

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Annotate a VM.
Expand Down Expand Up @@ -38,10 +38,10 @@
stop_on CMDS
end

vm_name = ARGV[0] or Trollop.die("no VM name given")
cmd = ARGV[1] or Trollop.die("no command given")
vm_name = ARGV[0] or Optimist.die("no VM name given")
cmd = ARGV[1] or Optimist.die("no command given")
abort "invalid command" unless CMDS.member? cmd
Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]

vim = VIM.connect opts

Expand All @@ -52,6 +52,6 @@
when 'get'
puts vm.config.annotation
when 'set'
value = ARGV[2] or Trollop.die("no annotation given")
value = ARGV[2] or Optimist.die("no annotation given")
vm.ReconfigVM_Task(:spec => VIM.VirtualMachineConfigSpec(:annotation => value)).wait_for_completion
end
16 changes: 8 additions & 8 deletions examples/cached_ovf_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Copyright (c) 2012-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'
require 'rbvmomi/utils/deploy'
require 'rbvmomi/utils/admission_control'
require 'yaml'

VIM = RbVmomi::VIM

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Deploy an OVF to a cluster, using a cached template if available.
Expand Down Expand Up @@ -45,12 +45,12 @@
opt :lease, "Lease in days", :type => :int, :default => 3
end

Trollop.die("must specify host") unless opts[:host]
Trollop.die("no cluster path given") unless opts[:computer_path]
Optimist.die("must specify host") unless opts[:host]
Optimist.die("no cluster path given") unless opts[:computer_path]
template_folder_path = opts[:template_path]
template_name = opts[:template_name] or Trollop.die("no template name given")
vm_name = ARGV[0] or Trollop.die("no VM name given")
ovf_url = ARGV[1] or Trollop.die("No OVF URL given")
template_name = opts[:template_name] or Optimist.die("no template name given")
vm_name = ARGV[0] or Optimist.die("no VM name given")
ovf_url = ARGV[1] or Optimist.die("No OVF URL given")

vim = VIM.connect opts
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
Expand Down
8 changes: 4 additions & 4 deletions examples/clone_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Clone a VM.
Expand All @@ -36,7 +36,7 @@
opt :linked_clone, "Use a linked clone instead of a full clone"
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
ARGV.size == 2 or abort "must specify VM source name and VM target name"
vm_source = ARGV[0]
vm_target = ARGV[1]
Expand Down
8 changes: 4 additions & 4 deletions examples/create_vm-1.9.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Create a VM.
Expand All @@ -34,7 +34,7 @@
EOS
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
vm_name = ARGV[0] or abort "must specify VM name"

vim = VIM.connect opts
Expand Down
8 changes: 4 additions & 4 deletions examples/create_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Create a VM.
Expand All @@ -34,7 +34,7 @@
EOS
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
vm_name = ARGV[0] or abort "must specify VM name"

vim = VIM.connect opts
Expand Down
8 changes: 4 additions & 4 deletions examples/delete_disk_from_vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Delete a disk from a VM.
Expand All @@ -29,7 +29,7 @@
rbvmomi_datacenter_opt
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
ARGV.size == 2 or abort "must specify VM name and disk unit number"
vm_name = ARGV[0]
disk_unit_number = ARGV[1].to_i
Expand Down
12 changes: 6 additions & 6 deletions examples/extraConfig.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM
CMDS = %w(list set)

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
View and modify VM extraConfig options.
Expand Down Expand Up @@ -38,10 +38,10 @@
stop_on CMDS
end

vm_name = ARGV[0] or Trollop.die("no VM name given")
cmd = ARGV[1] or Trollop.die("no command given")
vm_name = ARGV[0] or Optimist.die("no VM name given")
cmd = ARGV[1] or Optimist.die("no command given")
abort "invalid command" unless CMDS.member? cmd
Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]

vim = VIM.connect opts

Expand Down
12 changes: 6 additions & 6 deletions examples/lease_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# Copyright (c) 2012-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'
require 'rbvmomi/utils/leases'
require 'yaml'

VIM = RbVmomi::VIM
CMDS = ['set_lease_on_leaseless_vms', 'show_expired_vms',
'show_soon_expired_vms', 'kill_expired_vms']

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Tool for managing leases on VMs where leases are stored in YAML on VM annotations.
Expand Down Expand Up @@ -45,9 +45,9 @@
stop_on CMDS
end

Trollop.die("must specify host") unless opts[:host]
cmd = ARGV[0] or Trollop.die("no command given")
Trollop.die("no vm folder path given") unless opts[:vm_folder_path]
Optimist.die("must specify host") unless opts[:host]
cmd = ARGV[0] or Optimist.die("no command given")
Optimist.die("no vm folder path given") unless opts[:vm_folder_path]

vim = VIM.connect opts
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
Expand Down
8 changes: 4 additions & 4 deletions examples/logbundle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# SPDX-License-Identifier: MIT

# @todo Retrieve ESX log bundles when run against VC.
require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM
DEFAULT_SERVER_PLACEHOLDER = '0.0.0.0'

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Generate and retrieve a log bundle.
Expand All @@ -29,7 +29,7 @@
EOS
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
dest = ARGV[0] or abort("must specify destination directory")

abort "destination is not a directory" unless File.directory? dest
Expand Down
8 changes: 4 additions & 4 deletions examples/logtail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# SPDX-License-Identifier: MIT

# Translation of example 2-2 from the vSphere SDK for Perl Programming Guide
require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Follow a log file.
Expand All @@ -29,7 +29,7 @@
EOS
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
logKey = ARGV[0]

vim = VIM.connect opts
Expand Down
14 changes: 7 additions & 7 deletions examples/nfs_datastore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM
CMDS = %w(mount unmount)

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Mount/Unmount an NFS datastore from a cluster or single host system.
Expand Down Expand Up @@ -40,12 +40,12 @@
stop_on CMDS
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]

cr_path = ARGV[0] or Trollop.die("no system name given")
cmd = ARGV[1] or Trollop.die("no command given")
cr_path = ARGV[0] or Optimist.die("no system name given")
cmd = ARGV[1] or Optimist.die("no command given")
abort "invalid command" unless CMDS.member? cmd
nfs_spec = ARGV[2] or Trollop.die("no nfs path given")
nfs_spec = ARGV[2] or Optimist.die("no nfs path given")
remoteHost, remotePath = nfs_spec.split(":")
localPath = ARGV[3] || remoteHost
mode = "readOnly" #hardcoded.
Expand Down
12 changes: 6 additions & 6 deletions examples/power.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) 2011-2017 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: MIT

require 'trollop'
require 'optimist'
require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

VIM = RbVmomi::VIM
CMDS = %w(on off reset suspend destroy)

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Perform VM power operations.
Expand Down Expand Up @@ -37,9 +37,9 @@
stop_on CMDS
end

cmd = ARGV[0] or Trollop.die("no command given")
vm_name = ARGV[1] or Trollop.die("no VM name given")
Trollop.die("must specify host") unless opts[:host]
cmd = ARGV[0] or Optimist.die("no command given")
vm_name = ARGV[1] or Optimist.die("no VM name given")
Optimist.die("must specify host") unless opts[:host]

vim = VIM.connect opts

Expand Down
6 changes: 3 additions & 3 deletions examples/readme-1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# SPDX-License-Identifier: MIT

require 'rbvmomi'
require 'rbvmomi/trollop'
require 'rbvmomi/optimist'

opts = Trollop.options do
opts = Optimist.options do
banner <<-EOS
Example 1 from the README: Power on a VM.
Expand All @@ -29,7 +29,7 @@
EOS
end

Trollop.die("must specify host") unless opts[:host]
Optimist.die("must specify host") unless opts[:host]
vm_name = ARGV[0] or abort "must specify VM name"

vim = RbVmomi::VIM.connect opts
Expand Down
Loading

0 comments on commit a586755

Please sign in to comment.