Class: U3d::CommandsGenerator

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/u3d/commands_generator.rb

Overview

CLI using commander gem for u3d

Constant Summary collapse

UI =
U3dCore::UI

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



35
36
37
# File 'lib/u3d/commands_generator.rb', line 35

def self.start
  new.run
end

Instance Method Details

#convert_options(options) ⇒ Object



53
54
55
56
57
# File 'lib/u3d/commands_generator.rb', line 53

def convert_options(options)
  o = options.__hash__.dup
  o.delete(:verbose)
  o
end

#extract_run_args(args = ARGV) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/u3d/commands_generator.rb', line 39

def extract_run_args(args = ARGV)
  both_args = [[], []]
  idx = 0
  args.each do |arg|
    if arg == '--'
      idx = 1
      next
    end
    both_args[idx] << arg
  end
  args.replace both_args[0]
  both_args[1]
end

#runObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/u3d/commands_generator.rb', line 59

def run
  program :version, U3d::VERSION
  program :description, U3d::DESCRIPTION
  program :help, 'Authors', 'Jerome Lacoste <[email protected]>, Paul Niezborala <[email protected]>'
  program :help, 'A word on Unity versions', U3d::UNITY_VERSIONS_NOTE

  global_option('--verbose') { U3dCore::Globals.verbose = true }

  command :run do |c|
    # Intended for backward compatibilty purposes for run command
    # Meant to fetch options after '--' unknown by CommandsGenerator
    run_args = extract_run_args

    c.syntax = 'u3d run [-u | --unity_version <version>] [-r | --raw_logs] [ -- <run_args>]'
    c.description = 'Run unity, and parses its output through u3d\'s log prettifier'
    c.option '-u', '--unity_version STRING', String, 'Version of Unity to run with'
    c.option '-r', '--raw_logs', 'Raw Unity output, not filtered by u3d\'s log prettifier'
    c.action do |args, options|
      UI.user_error! "Run doesn't take arguments. Did you forget '--' or did you mistake your command? (#{args})" if args.count > 0
      U3dCore::Globals.log_timestamps = true
      Commands.run(options: convert_options(options), run_args: run_args)
    end
  end

  command :list do |c|
    c.syntax = 'u3d list [-p | --packages]'
    c.option '-p', '--packages', 'Lists installed packages as well'
    c.example 'List currently installed Unity3d versions, as well as installed packages', 'u3d list -p'
    c.description = 'List installed version of Unity3d'
    c.action do |_args, options|
      Commands.list_installed(options: convert_options(options))
    end
  end

  command :available do |c|
    oses = U3dCore::Helper.operating_systems
    c.syntax = 'u3d available [-r | --release_level <level>] [-o | --operating_system <OS>] [-u | --unity_version <version>] [-p | --packages] [-f | --force]'
    levels = Commands.release_levels
    c.option '-f', '--force', 'Force refresh list of available versions'
    c.option '-r', '--release_level STRING', String, "Checks for availability on specific release level [#{levels.join(',')}]"
    c.option '-o', '--operating_system STRING', String, "Checks for availability on specific OS [#{oses.join(', ')}]"
    c.option '-u', '--unity_version STRING', String, 'Checks if specified version is available'
    c.option '-p', '--packages', 'Lists available packages as well'
    c.example 'List all versions available, forcing a refresh of the available packages from Unity servers', 'u3d available -f'
    c.example 'List stable versions available', 'u3d available -r stable -p'
    c.example 'List all versions available for Linux platform', 'u3d available -o linux'
    c.example 'List packages available for Unity version 5.6.0f3', 'u3d available -u 5.6.0f3 -p'
    c.description = 'List download-ready versions of Unity3d'
    c.action do |_args, options|
      options.default packages: false
      Commands.list_available(options: convert_options(options))
    end
  end

  command :install do |c|
    c.syntax = 'u3d install <version> [ [-p | --packages <package> ...] | [-a | --all] ] [ [-n | --no_install] [-i | --installation_path <path>] ]'
    c.description = "Download (and install) Unity3D packages."
    c.option '-p', '--packages PACKAGES', Array, 'Specifies which packages to download. Overriden by --all'
    c.option '-i', '--installation_path PATH', String, 'Specifies where package(s) will be installed. Overriden by --no_install'
    c.option '-a', '--all', 'Download all available packages'
    c.option '-n', '--no_install', 'No installation after download success'
    c.option '-k', '--keychain', 'Gain privileges right through the keychain. [OSX only]'
    c.example 'Download and install Unity, its Documentation and the Android build support and install them for version 5.1.2f1', 'u3d install 5.1.2f1 -p Unity,Documentation,Android'
    c.example "The 'version' argument can be a specific version number, such as 5.6.1f1, or an alias in [#{Commands.release_letter_mapping.keys.join(',')}]", 'u3d install latest'
    c.action do |args, options|
      options.default all: false
      options.default no_install: false
      Commands.download(args: args, options: convert_options(options))
    end
  end

  command :local_install do |c|
    c.syntax = 'u3d local_install <version> [ [-p | --packages <package> ...] | [-a | --all] ] [-i | --installation_path <path>]'
    c.description = 'Install downloaded version of unity'
    c.option '-p', '--packages PACKAGES', Array, 'Specifies which packages to install. Overriden by --all'
    c.option '-i', '--installation_path PATH', String, 'Specifies where package(s) will be installed.'
    c.option '-a', '--all', 'Install all downloaded packages'
    c.option '-k', '--keychain', 'Gain privileges right through the keychain. [OSX only]'
    c.action do |args, options|
      Commands.local_install(args: args, options: convert_options(options))
    end
  end

  command :credentials do |c|
    c.syntax = "u3d credentials <#{Commands.credentials_actions.join(' | ')}>"
    c.description = 'Manages keychain credentials so u3d remembers them. [OSX only]'
    c.action do |args, options|
      Commands.credentials(args: args, options: convert_options(options))
    end
  end

  command :prettify do |c|
    c.syntax = 'u3d prettify <logfile>'
    c.description = 'Prettify a saved logfile'
    c.action do |args, _options|
      Commands.local_analyze(args: args)
    end
  end

  default_command :run

  run!
end