Skip to content

Commit

Permalink
Merge pull request #37 from github/kpaulisse-option-sorting
Browse files Browse the repository at this point in the history
Consistent sorting of equally weighted command line options
  • Loading branch information
kpaulisse authored Dec 30, 2016
2 parents 76bb22b + 681345d commit 13f0cb7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
60 changes: 30 additions & 30 deletions doc/optionsref.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,59 +64,59 @@ Usage: octocatalog-diff [command line options]
--[no-]display-datatype-changes
Display changes in data type even when strings match
--[no-]catalog-only Only compile the catalog for the "to" branch but do not diff
--[no-]from-puppetdb Pull "from" catalog from PuppetDB instead of compiling
--[no-]parallel Enable or disable parallel processing
--puppet-binary STRING Full path to puppet binary globally
--to-puppet-binary STRING Full path to puppet binary for the to branch
--from-puppet-binary STRING Full path to puppet binary for the from branch
--[no-]parallel Enable or disable parallel processing
--[no-]from-puppetdb Pull "from" catalog from PuppetDB instead of compiling
--puppetdb-ssl-client-password-file FILENAME
Read password for SSL client key from a file
--facts-terminus STRING Facts terminus: one of yaml, facter
--puppetdb-ssl-ca FILENAME CA certificate that signed the PuppetDB certificate
--puppetdb-ssl-client-password PASSWORD
Password for SSL client key to connect to PuppetDB
--puppetdb-ssl-client-key FILENAME
SSL client key to connect to PuppetDB
--puppetdb-ssl-ca FILENAME CA certificate that signed the PuppetDB certificate
--puppetdb-ssl-client-cert FILENAME
SSL client certificate to connect to PuppetDB
--facts-terminus STRING Facts terminus: one of yaml, facter
--puppetdb-ssl-client-key FILENAME
SSL client key to connect to PuppetDB
--puppetdb-ssl-client-password-file FILENAME
Read password for SSL client key from a file
--puppetdb-url URL PuppetDB base URL
--puppetdb-api-version N Version of PuppetDB API (3 or 4)
--puppet-master-ssl-ca STRING
Full path to CA certificate that signed the Puppet Master certificate globally
--to-puppet-master-ssl-ca STRING
Full path to CA certificate that signed the Puppet Master certificate for the to branch
--from-puppet-master-ssl-ca STRING
Full path to CA certificate that signed the Puppet Master certificate for the from branch
--puppet-master-ssl-client-key STRING
Full path to key file for SSL client auth to Puppet Master globally
--to-puppet-master-ssl-client-key STRING
Full path to key file for SSL client auth to Puppet Master for the to branch
--from-puppet-master-ssl-client-key STRING
Full path to key file for SSL client auth to Puppet Master for the from branch
--fact-override STRING1[,STRING2[,...]]
Override fact globally
--to-fact-override STRING1[,STRING2[,...]]
Override fact for the to branch
--from-fact-override STRING1[,STRING2[,...]]
Override fact for the from branch
--puppet-master-ssl-client-cert STRING
Full path to certificate file for SSL client auth to Puppet Master globally
--to-puppet-master-ssl-client-cert STRING
Full path to certificate file for SSL client auth to Puppet Master for the to branch
--from-puppet-master-ssl-client-cert STRING
Full path to certificate file for SSL client auth to Puppet Master for the from branch
--puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master globally
--to-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the to branch
--from-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the from branch
--puppet-master-api-version STRING
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) globally
--to-puppet-master-api-version STRING
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) for the to branch
--from-puppet-master-api-version STRING
Puppet Master API version (2 for Puppet 3.x, 3 for Puppet 4.x) for the from branch
--puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master globally
--to-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the to branch
--from-puppet-master STRING Hostname or Hostname:PortNumber for Puppet Master for the from branch
--puppet-master-ssl-ca STRING
Full path to CA certificate that signed the Puppet Master certificate globally
--to-puppet-master-ssl-ca STRING
Full path to CA certificate that signed the Puppet Master certificate for the to branch
--from-puppet-master-ssl-ca STRING
Full path to CA certificate that signed the Puppet Master certificate for the from branch
--puppet-master-ssl-client-cert STRING
Full path to certificate file for SSL client auth to Puppet Master globally
--to-puppet-master-ssl-client-cert STRING
Full path to certificate file for SSL client auth to Puppet Master for the to branch
--from-puppet-master-ssl-client-cert STRING
Full path to certificate file for SSL client auth to Puppet Master for the from branch
--puppet-master-ssl-client-key STRING
Full path to key file for SSL client auth to Puppet Master globally
--to-puppet-master-ssl-client-key STRING
Full path to key file for SSL client auth to Puppet Master for the to branch
--from-puppet-master-ssl-client-key STRING
Full path to key file for SSL client auth to Puppet Master for the from branch
--pe-enc-url URL Base URL for Puppet Enterprise ENC endpoint
--pe-enc-token-file PATH Path containing token for PE node classifier, relative or absolute
--pe-enc-token TOKEN Token to access the Puppet Enterprise ENC API
--pe-enc-token-file PATH Path containing token for PE node classifier, relative or absolute
--pe-enc-ssl-ca FILENAME CA certificate that signed the ENC API certificate
--pe-enc-ssl-client-cert FILENAME
SSL client certificate to connect to PE ENC
Expand Down
14 changes: 12 additions & 2 deletions lib/octocatalog-diff/catalog-diff/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def self.weight
@weight || DEFAULT_WEIGHT
end

def self.name
self::NAME
end

def self.newoption(name, &block)
klass = Class.new(OctocatalogDiff::CatalogDiff::Cli::Options::Option)
klass.const_set('NAME', name)
Expand Down Expand Up @@ -61,12 +65,18 @@ def self.parse_options(argv, defaults = {})
end

# Read in *.rb files in the 'options' directory and create classes from them.
# Sort the classes according to weight and return the list of sorted classes.
# Sort the classes according to weight and name and return the list of sorted classes.
# @return [Array<Class>] Sorted classes
def self.option_classes
files = Dir.glob(File.join(File.dirname(__FILE__), 'options', '*.rb'))
files.each { |file| load file } # Populates self.classes
classes.sort { |a, b| a.weight <=> b.weight }
classes.sort do |a, b|
[
a.weight <=> b.weight,
a.name.downcase <=> b.name.downcase,
a.object_id <=> b.object_id
].find(&:nonzero?)
end
end

# Sets up options that can be defined globally or for just one branch. For example, with a
Expand Down

0 comments on commit 13f0cb7

Please sign in to comment.