hammer_cli 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/config/cli_config.template.yml +12 -3
  4. data/doc/creating_apipie_commands.md +53 -56
  5. data/doc/creating_commands.md +25 -19
  6. data/doc/developer_docs.md +3 -2
  7. data/doc/development_tips.md +3 -3
  8. data/doc/i18n.md +3 -3
  9. data/doc/installation.md +24 -207
  10. data/doc/installation_deb.md +48 -0
  11. data/doc/installation_gem.md +30 -0
  12. data/doc/installation_rpm.md +53 -0
  13. data/doc/installation_source.md +31 -0
  14. data/doc/option_builders.md +77 -0
  15. data/doc/option_normalizers.md +5 -5
  16. data/doc/writing_a_plugin.md +9 -9
  17. data/lib/hammer_cli.rb +1 -0
  18. data/lib/hammer_cli/abstract.rb +21 -8
  19. data/lib/hammer_cli/apipie.rb +1 -2
  20. data/lib/hammer_cli/apipie/command.rb +37 -64
  21. data/lib/hammer_cli/apipie/option_builder.rb +69 -0
  22. data/lib/hammer_cli/apipie/options.rb +1 -61
  23. data/lib/hammer_cli/clamp.rb +15 -0
  24. data/lib/hammer_cli/i18n.rb +14 -2
  25. data/lib/hammer_cli/logger.rb +1 -1
  26. data/lib/hammer_cli/option_builder.rb +43 -0
  27. data/lib/hammer_cli/options/option_definition.rb +6 -0
  28. data/lib/hammer_cli/output/adapter/abstract.rb +2 -2
  29. data/lib/hammer_cli/output/adapter/base.rb +6 -3
  30. data/lib/hammer_cli/output/adapter/table.rb +19 -2
  31. data/lib/hammer_cli/output/definition.rb +4 -0
  32. data/lib/hammer_cli/output/fields.rb +9 -0
  33. data/lib/hammer_cli/output/formatters.rb +20 -8
  34. data/lib/hammer_cli/utils.rb +1 -1
  35. data/lib/hammer_cli/version.rb +1 -1
  36. data/locale/hammer-cli.pot +103 -79
  37. data/test/unit/abstract_test.rb +62 -0
  38. data/test/unit/apipie/command_test.rb +12 -197
  39. data/test/unit/apipie/option_builder_test.rb +110 -0
  40. data/test/unit/i18n_test.rb +50 -0
  41. data/test/unit/option_builder_test.rb +33 -0
  42. data/test/unit/output/adapter/abstract_test.rb +26 -3
  43. data/test/unit/output/adapter/base_test.rb +20 -3
  44. data/test/unit/output/adapter/csv_test.rb +2 -2
  45. data/test/unit/output/adapter/table_test.rb +24 -1
  46. data/test/unit/output/definition_test.rb +13 -0
  47. data/test/unit/output/formatters_test.rb +17 -1
  48. data/test/unit/utils_test.rb +1 -1
  49. metadata +101 -88
  50. data/lib/hammer_cli/apipie/read_command.rb +0 -41
  51. data/lib/hammer_cli/apipie/write_command.rb +0 -49
  52. data/test/unit/apipie/read_command_test.rb +0 -37
  53. data/test/unit/apipie/write_command_test.rb +0 -41
@@ -3,12 +3,13 @@ Hammer Development Docs
3
3
 
4
4
  Hammer is a generic clamp-based CLI framework. It uses existing clamp features and adds some extra utilities.
5
5
  We recommend to get familiar with the [Clamp documentation](https://github.com/mdub/clamp/#quick-start)
6
- before creating some hammer specific plugins.
6
+ before creating hammer specific plugins.
7
7
 
8
8
  Contents:
9
9
  - [Writing a plugin](writing_a_plugin.md#writing-your-own-hammer-plugin)
10
10
  - [Creating commands](creating_commands.md#create-your-first-command)
11
+ - [Option builders](option_builders.md#option-builders)
11
12
  - [Creating ApiPie commands](creating_apipie_commands.md#creating-commands-for-restful-api-with-apipie)
12
13
  - [Development tips](development_tips.md#development-tips)
13
14
  - [Option normalizers](option_normalizers.md#option-normalizers)
14
- - [Internacionalization](i18n.md#internacionalization)
15
+ - [Internationalization](i18n.md#internationalization)
@@ -2,7 +2,7 @@ Development Tips
2
2
  ----------------
3
3
 
4
4
  ### Local gem modifications
5
- If you want to modify gems setup for development needs, create a file `Gemfile.local` in the root of your hammer-cli checkout. You can override the setup from `Gemfile` there. This file is git-ignored so you can easily keep your custom tuning.
5
+ If you want to modify the gems setup for development needs, create a file `Gemfile.local` in the root of your hammer-cli checkout. You can override the setup from `Gemfile` there. This file is git-ignored so you can easily keep your custom tuning.
6
6
 
7
7
  Typical usage is for linking plugins from local checkouts:
8
8
  ```ruby
@@ -11,9 +11,9 @@ gem 'hammer_cli_foreman', :path => '../hammer-cli-foreman'
11
11
 
12
12
  ### Debugging with Pry
13
13
  [Pry](https://github.com/pry/pry) is a runtime developer console for ruby.
14
- It allows for debugging when [Pry Debugger](https://github.com/nixme/pry-debugger) is installed alongside.
14
+ It allows debugging when [Pry Debugger](https://github.com/nixme/pry-debugger) is installed alongside.
15
15
 
16
- For basic usage, add following lines to your `Gemfile.local`:
16
+ For basic usage, add following the lines to your `Gemfile.local`:
17
17
 
18
18
  ```ruby
19
19
  gem 'pry'
@@ -1,4 +1,4 @@
1
- Internacionalization
1
+ Internationalization
2
2
  --------------------
3
3
 
4
4
  Hammer uses [fast gettext](https://github.com/grosser/fast_gettext) for string translations. Most of the localization magic
@@ -46,7 +46,7 @@ HammerCLI::I18n.add_domain(HammerCLIAwesomePlugin::I18n::LocaleDomain.new)
46
46
  ```
47
47
 
48
48
  Then you have to export strings, translate them and place the files in a directory structure.
49
- Inspiration on how to export the translations can be found in the hammer's [Rakefile](../Rakefile).
49
+ Inspiration on how to export the translations can be found in hammer's [Rakefile](../Rakefile).
50
50
 
51
51
  Typical directory structure for translation files look like this:
52
52
  ```
@@ -65,7 +65,7 @@ locale
65
65
 
66
66
  ### Translation tips
67
67
 
68
- When writing a code with translations make sure you keep two following rules:
68
+ When writing code with translations make sure you keep two following rules:
69
69
 
70
70
  1) Don't use variables directly in the strings and make formatting substitutions outside the gettext function `_("...")`.
71
71
  ```ruby
@@ -8,161 +8,11 @@ Hammer CLI is packaged for the following RPM based distributions:
8
8
  - Debian Wheezy, Squeezy
9
9
  - Ubuntu Precise
10
10
 
11
- ### Installation from RPMs
12
-
13
- #### Step 1: setup yum repositories
14
-
15
- For Foreman 1.3 stable the hammer packages are part of your installation repo and you can skip this step.
16
-
17
- You can choose from stable or nightly repo. Nightly has more recent version of hammer packages, but it was subject to less testing so there is a higher risk of issues.
18
- Add the Foreman yum repository to your yum repo files. For Fedora installations replace 'el6' with 'f18' or 'f19' as appropriate.
19
-
20
-
21
- Using stable
22
-
23
- ```bash
24
- yum -y install http://yum.theforeman.org/releases/1.3/el6/x86_64/foreman-release.rpm
25
- ```
26
-
27
- or nightly
28
-
29
- ```bash
30
- cat > /etc/yum.repos.d/foreman.repo << EOF
31
- [foreman]
32
- name=Foreman Nightly
33
- baseurl=http://yum.theforeman.org/nightly/el6/x86_64
34
- gpgcheck=0
35
- enabled=1
36
- EOF
37
- ```
38
-
39
- On RHEL systems you will also have to add [EPEL repository](https://fedoraproject.org/wiki/EPEL) as it contains some of the required dependencies.
40
-
41
-
42
- #### Step 2: install hammer core
43
-
44
- ```bash
45
- yum install rubygem-hammer_cli
46
- ```
47
-
48
- #### Step 3: install plugins
49
- Currently, there are two plugins, both available as rpm packages.
50
-
51
- - commands for managing foreman
52
-
53
- ```bash
54
- yum install rubygem-hammer_cli_foreman
55
- ```
56
-
57
- - commands for katello [katello cli](https://github.com/Katello/katello)
58
-
59
- ```bash
60
- yum install rubygem-hammer_cli_katello
61
- ```
62
-
63
- To install any other hammer plugin just make sure the appropriate gem is installed and follow with the configuration.
64
-
65
-
66
- ### Installation from DEBs
67
-
68
- #### Step 1: setup apt repositories
69
-
70
- For Foreman 1.3 stable the hammer packages are part of your installation repo and you can skip this step.
71
-
72
- You can choose from stable or nightly repo. Nightly has more recent version of hammer packages, but it was subject to less testing so there is a highr risk of issues.
73
-
74
- Choose stable (don't forget to replace "squeeze" with version name of your system)
75
-
76
- ```bash
77
- echo "deb http://deb.theforeman.org/ squeeze stable" > /etc/apt/sources.list.d/foreman.list
78
- ```
79
-
80
- or nightly
81
-
82
- ```bash
83
- echo "deb http://deb.theforeman.org/ squeeze nightly" > /etc/apt/sources.list.d/foreman.list
84
- ```
85
-
86
- and update the keys
87
-
88
- ```bash
89
- wget -q http://deb.theforeman.org/foreman.asc -O- | apt-key add -
90
- ```
91
-
92
- #### Step 2: install hammer core
93
-
94
- ```bash
95
- apt-get update && apt-get install ruby-hammer-cli
96
- ```
97
-
98
- #### Step 3: install plugins
99
- Currently, there are two plugins, both available as deb packages.
100
-
101
- - commands for managing foreman
102
-
103
- ```bash
104
- $ apt-get install ruby-hammer-cli-foreman
105
- ```
106
-
107
- - 1:1 bridge to [katello cli](https://github.com/Katello/katello)
108
-
109
- ```bash
110
- $ apt-get install ruby-hammer-cli-katello
111
- ```
112
-
113
- To install any other hammer plugin just make sure the appropriate gem is installed and follow with the configuration.
114
-
115
-
116
- ### Installation from GEMs
117
-
118
- Make sure you have ```gem``` command installed on your system
119
-
120
- #### Step 1: install hammer core
121
-
122
- ```bash
123
- $ gem install hammer_cli
124
- ```
125
-
126
- #### Step 2: install plugins
127
- Currently, there are two plugins, both available on rubygems.org
128
-
129
- - commands for managing foreman
130
-
131
- ```bash
132
- $ gem install hammer_cli_foreman
133
- ```
134
-
135
- - 1:1 bridge to [katello cli](https://github.com/Katello/katello)
136
-
137
- ```bash
138
- $ gem install hammer_cli_katello
139
- ```
140
-
141
- To install any other hammer plugin just install the appropriate gem and follow with the configuration.
142
-
143
-
144
- ### Installation from SOURCE
145
-
146
- If you can install hammer from git checkouts, you will just need ```rake``` installed on your system.
147
- Clone and install CLI core
148
-
149
- ```bash
150
- $ git clone https://github.com/theforeman/hammer-cli.git
151
- $ cd hammer-cli
152
- $ rake install
153
- $ cd ..
154
- ```
155
-
156
- clone plugin with foreman commands
157
-
158
- ```bash
159
- $ git clone https://github.com/theforeman/hammer-cli-foreman.git
160
- $ cd hammer-cli-foreman
161
- $ rake install
162
- $ cd ..
163
- ```
164
-
165
- and optionally other plugins via any of the methods mentioned above.
11
+ ### Select your way of installation
12
+ - [Installation from RPMs](installation_rpm.md#installation-from-rpms)
13
+ - [Installation from DEBs](installation_deb.md#installation-from-debs)
14
+ - [Installation from GEMs](installation_gem.md#installation-from-gems)
15
+ - [Installation from source](installation_source.md#installation-from-source)
166
16
 
167
17
 
168
18
  Configuration
@@ -184,51 +34,30 @@ the ```cli.modules.d``` subdirectory which is place for specific configuration o
184
34
  Later directories and files have precedence if they redefine the same option. Files from ```cli.modules.d```
185
35
  are loaded in alphabetical order.
186
36
 
187
- ### Format
37
+ ### Manual installation
38
+ The packaged version of hammer copies the template to `/etc/hammer` for you.
39
+ When you install from gems or source you'll have to copy config files manually.
188
40
 
189
- Hammer uses yaml formatting for its configuration. The configuration templates are contained in the hammer_cli gem
41
+ The configuration templates are contained in the hammer_cli gem
190
42
 
191
43
  ```bash
192
44
  gem contents hammer_cli|grep template.yml
193
45
  ```
194
- and can be copied to one of the locations above and changed as needed. The packaged version of hammer copies the template to /etc for you.
195
-
196
-
197
- ### Options
198
-
199
- - ```:log_dir: <path>``` - directory where the logs are stored. The default is ```/var/log/hammer/``` and the log file is named ```hammer.log```
200
- - ```:log_level: <level>``` - logging level. One of ```debug```, ```info```, ```warning```, ```error```, ```fatal```
201
- - ```:log_owner: <owner>``` - logfile owner
202
- - ```:log_group: <group>``` - logfile group
203
- - ```:log_size: 1048576``` - size in bytes, when exceeded the log rotates. Default is 1MB
204
- - ```:watch_plain: <bool>``` - turn on/off syntax highlighting of data being logged in debug mode
205
- - ```:log_api_calls: <bool>``` - turn on logging of the communication with API (data sent and received)
46
+ and can be copied to one of the locations above and changed as needed.
206
47
 
207
- In the ```:ui``` section there is
208
48
 
209
- - ```:interactive: <bool>``` - whether to ask user for input (pagination, passwords)
210
- - ```:per_page: <records>``` - number of records per page if server sends paginated data
211
- - ```:history_file: <path>``` - file where the hammer shell store its history (default is ```~/.hammer_history```)
49
+ ### Tuning options
212
50
 
51
+ Hammer uses [YAML](http://www.yaml.org/) formatting for its configuration.
213
52
 
214
- #### Sample config
53
+ List of existing options is available in the [configuration template file](https://github.com/theforeman/hammer-cli/blob/master/config/cli_config.template.yml)
54
+ with descriptions.
215
55
 
216
- ```yaml
217
- :ui:
218
- :interactive: true
219
- :per_page: 20
220
- :history_file: '~/.hammer/history'
221
-
222
- :watch_plain: false
223
-
224
- :log_dir: '~/.hammer/log'
225
- :log_level: 'error'
226
- :log_api_calls: false
227
- ```
228
56
 
229
57
  ### Plugins
230
58
 
231
- Plugins are disabled by default. To enable plugin create configuration file in ```cli.modules.d``` and add```:enable_plugin: true``` in it. Plugin specific configuration should be nested under plugin's name (without the ```hammer_cli_``` prefix).
59
+ Plugins are disabled by default. To enable plugin create configuration file in ```cli.modules.d``` and add```:enable_plugin: true``` in it.
60
+ Plugin specific configuration must be nested under plugin's name (without the ```hammer_cli_``` prefix).
232
61
 
233
62
  In the example we assume the gem ```hammer_cli_foreman``` with the Foreman plugin is installed. Then the plugin configuration
234
63
  in ```~/.hammer/cli.plugins.d/foreman.yml``` should look as follows:
@@ -256,38 +85,26 @@ Parameters:
256
85
  [ARG] ... subcommand arguments
257
86
 
258
87
  Subcommands:
259
- activation-key Manipulate activation keys.
260
88
  architecture Manipulate architectures.
261
- compute_resource Manipulate compute resources.
89
+ compute-resource Manipulate compute resources.
262
90
  domain Manipulate domains.
263
91
  environment Manipulate environments.
264
92
  fact Search facts.
265
- global_parameter Manipulate global parameters.
266
- gpg manipulate GPG Key actions on the server
93
+ global-parameter Manipulate global parameters.
267
94
  host Manipulate hosts.
268
95
  hostgroup Manipulate hostgroups.
269
- lifecycle-environment manipulate lifecycle_environments on the server
270
96
  location Manipulate locations.
271
97
  medium Manipulate installation media.
272
98
  model Manipulate hardware models.
273
- organization Manipulate organizations
99
+ organization Manipulate organizations.
274
100
  os Manipulate operating system.
275
- partition_table Manipulate partition tables.
276
- ping get the status of the server
277
- product Manipulate products.
278
- provider Manipulate providers
101
+ partition-table Manipulate partition tables.
279
102
  proxy Manipulate smart proxies.
280
- puppet_class Search puppet modules.
103
+ puppet-class Search puppet modules.
281
104
  report Browse and read reports.
282
- repository Manipulate repositories
283
- repository-set manipulate repository sets on the server
284
- sc_param Manipulate smart class parameters.
105
+ sc-param Manipulate smart class parameters.
285
106
  shell Interactive shell
286
107
  subnet Manipulate subnets.
287
- subscription Manipulate subscriptions.
288
- system manipulate systems on the server
289
- systemgroup Manipulate system groups
290
- task Tasks related actions.
291
108
  template Manipulate config templates.
292
109
  user Manipulate users.
293
110
 
@@ -297,7 +114,7 @@ Options:
297
114
  --csv-separator SEPARATOR Character to separate the values
298
115
  --interactive INTERACTIVE Explicitly turn interactive mode on/off
299
116
  One of true/false, yes/no, 1/0.
300
- --output ADAPTER Set output format. One of [base, table, silent, csv]
117
+ --output ADAPTER Set output format. One of [silent, csv, base, table]
301
118
  --show-ids Show ids of associated resources
302
119
  --version show version
303
120
  -c, --config CFG_FILE path to custom config file
@@ -308,7 +125,7 @@ Options:
308
125
  ```
309
126
 
310
127
 
311
- And you are Done. Your hammer client is configured and ready to use.
128
+ And you are done. Your hammer client is configured and ready to use.
312
129
 
313
130
 
314
131
  Autocompletion
@@ -0,0 +1,48 @@
1
+ ### Installation from DEBs
2
+
3
+ #### Step 1: setup apt repositories
4
+
5
+ For Foreman 1.3 stable the hammer packages are part of your installation repo and you can skip this step.
6
+
7
+ You can choose from stable or nightly repo. Nightly has more recent version of hammer packages, but it was subject to less testing so there is a highr risk of issues.
8
+
9
+ Choose stable (don't forget to replace "squeeze" with version name of your system)
10
+
11
+ ```bash
12
+ echo "deb http://deb.theforeman.org/ squeeze stable" > /etc/apt/sources.list.d/foreman.list
13
+ ```
14
+
15
+ or nightly
16
+
17
+ ```bash
18
+ echo "deb http://deb.theforeman.org/ squeeze nightly" > /etc/apt/sources.list.d/foreman.list
19
+ ```
20
+
21
+ and update the keys
22
+
23
+ ```bash
24
+ wget -q http://deb.theforeman.org/foreman.asc -O- | apt-key add -
25
+ ```
26
+
27
+ #### Step 2: install hammer core
28
+
29
+ ```bash
30
+ apt-get update && apt-get install ruby-hammer-cli
31
+ ```
32
+
33
+ #### Step 3: install plugins
34
+ Currently, there are two plugins, both available as deb packages.
35
+
36
+ - commands for managing foreman
37
+
38
+ ```bash
39
+ $ apt-get install ruby-hammer-cli-foreman
40
+ ```
41
+
42
+ - commands for managing [katello](https://github.com/Katello/katello)
43
+
44
+ ```bash
45
+ $ apt-get install ruby-hammer-cli-katello
46
+ ```
47
+
48
+ To install any other hammer plugin just make sure the appropriate gem is installed and follow with the [configuration](installation.md#configuration).
@@ -0,0 +1,30 @@
1
+ ### Installation from GEMs
2
+
3
+ Make sure you have ```gem``` command installed on your system
4
+
5
+ #### Step 1: install hammer core
6
+
7
+ ```bash
8
+ $ gem install hammer_cli
9
+ ```
10
+
11
+ #### Step 2: install plugins
12
+ Currently, there are two plugins, both available on rubygems.org
13
+
14
+ - commands for managing foreman
15
+
16
+ ```bash
17
+ $ gem install hammer_cli_foreman
18
+ ```
19
+
20
+ - commands for managing [katello](https://github.com/Katello/katello)
21
+
22
+ ```bash
23
+ $ gem install hammer_cli_katello
24
+ ```
25
+
26
+ #### Step 3: enable and configure the plugins
27
+ Installation via gems unfortunately won't create configuration files.
28
+ You'll have to copy them to proper locations manually.
29
+ Please check our [configuration instructions](installation.md#configuration).
30
+
@@ -0,0 +1,53 @@
1
+ ### Installation from RPMs
2
+
3
+ #### Step 1: setup yum repositories
4
+
5
+ For Foreman 1.3 stable the hammer packages are part of your installation repo and you can skip this step.
6
+
7
+ You can choose from stable or nightly repo. Nightly has more recent version of hammer packages, but it was subject to less testing so there is a higher risk of issues.
8
+ Add the Foreman yum repository to your yum repo files. For Fedora installations replace 'el6' with 'f18' or 'f19' as appropriate.
9
+
10
+
11
+ Using stable
12
+
13
+ ```bash
14
+ yum -y install http://yum.theforeman.org/releases/1.3/el6/x86_64/foreman-release.rpm
15
+ ```
16
+
17
+ or nightly
18
+
19
+ ```bash
20
+ cat > /etc/yum.repos.d/foreman.repo << EOF
21
+ [foreman]
22
+ name=Foreman Nightly
23
+ baseurl=http://yum.theforeman.org/nightly/el6/x86_64
24
+ gpgcheck=0
25
+ enabled=1
26
+ EOF
27
+ ```
28
+
29
+ On RHEL systems you will also have to add [EPEL repository](https://fedoraproject.org/wiki/EPEL) as it contains some of the required dependencies.
30
+
31
+
32
+ #### Step 2: install hammer core
33
+
34
+ ```bash
35
+ yum install rubygem-hammer_cli
36
+ ```
37
+
38
+ #### Step 3: install plugins
39
+ Currently, there are two plugins, both available as rpm packages.
40
+
41
+ - commands for managing foreman
42
+
43
+ ```bash
44
+ yum install rubygem-hammer_cli_foreman
45
+ ```
46
+
47
+ - commands for managing [katello](https://github.com/Katello/katello)
48
+
49
+ ```bash
50
+ yum install rubygem-hammer_cli_katello
51
+ ```
52
+
53
+ To install any other hammer plugin just make sure the appropriate gem is installed and follow with the [configuration](installation.md#configuration).