yaml_command 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.index +58 -0
- data/HISTORY.md +23 -0
- data/LICENSE.txt +27 -0
- data/README.md +94 -0
- data/bin/yaml +9 -0
- data/lib/yaml_command.rb +49 -0
- data/lib/yaml_command.yml +58 -0
- data/lib/yaml_command/base.rb +139 -0
- data/lib/yaml_command/edit.rb +42 -0
- data/lib/yaml_command/get.rb +30 -0
- data/lib/yaml_command/set.rb +36 -0
- data/lib/yaml_command/slurp.rb +52 -0
- data/lib/yaml_command/sort.rb +52 -0
- data/lib/yaml_command/splat.rb +130 -0
- data/lib/yaml_command/view.rb +49 -0
- data/man/yaml-edit.1 +24 -0
- data/man/yaml-edit.1.html +107 -0
- data/man/yaml-edit.1.ronn +26 -0
- data/man/yaml-get.1 +30 -0
- data/man/yaml-get.1.html +109 -0
- data/man/yaml-get.1.ronn +30 -0
- data/man/yaml-set.1 +30 -0
- data/man/yaml-set.1.html +109 -0
- data/man/yaml-set.1.ronn +30 -0
- data/man/yaml-slurp.1 +30 -0
- data/man/yaml-slurp.1.html +109 -0
- data/man/yaml-slurp.1.ronn +30 -0
- data/man/yaml-splat.1 +30 -0
- data/man/yaml-splat.1.html +110 -0
- data/man/yaml-splat.1.ronn +31 -0
- data/man/yaml-view.1 +24 -0
- data/man/yaml-view.1.html +105 -0
- data/man/yaml-view.1.ronn +24 -0
- data/man/yaml.1 +45 -0
- data/man/yaml.1.html +126 -0
- data/man/yaml.1.ronn +51 -0
- metadata +151 -0
data/.index
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
type: ruby
|
3
|
+
revision: 2013
|
4
|
+
sources:
|
5
|
+
- Index.yml
|
6
|
+
authors:
|
7
|
+
- name: Thomas Sawyer
|
8
|
+
email: transfire@gmail.com
|
9
|
+
organizations:
|
10
|
+
- name: Rubyworks
|
11
|
+
requirements:
|
12
|
+
- name: ansi
|
13
|
+
- name: executable
|
14
|
+
- groups:
|
15
|
+
- build
|
16
|
+
development: true
|
17
|
+
name: detroit
|
18
|
+
- groups:
|
19
|
+
- test
|
20
|
+
development: true
|
21
|
+
name: qed
|
22
|
+
conflicts: []
|
23
|
+
alternatives: []
|
24
|
+
resources:
|
25
|
+
- type: home
|
26
|
+
uri: http://rubyworks.github.com/yaml_command
|
27
|
+
label: Homepage
|
28
|
+
- type: code
|
29
|
+
uri: http://github.com/rubyworks/yaml_command
|
30
|
+
label: Source Code
|
31
|
+
- type: bugs
|
32
|
+
uri: http://github.com/rubyworks/yaml_command/issues
|
33
|
+
label: Issue Tracker
|
34
|
+
- type: mail
|
35
|
+
uri: http://groups.google.com/rubyworks-mailinglist
|
36
|
+
label: Mailing List
|
37
|
+
- type: chat
|
38
|
+
uri: irc://chat.us.freenode.net/rubyworks
|
39
|
+
label: IRC Channel
|
40
|
+
repositories:
|
41
|
+
- name: upstream
|
42
|
+
scm: git
|
43
|
+
uri: git://github.com/rubyworks/yaml_command.git
|
44
|
+
categories: []
|
45
|
+
load_path:
|
46
|
+
- lib
|
47
|
+
copyrights:
|
48
|
+
- holder: RubyWorks
|
49
|
+
year: '2011'
|
50
|
+
license: BSD-2-Clause
|
51
|
+
name: yaml_command
|
52
|
+
title: YAML Command
|
53
|
+
version: 0.1.0
|
54
|
+
summary: Command-line access to YAML files.
|
55
|
+
description: YAML Command provides a command line interface to teasing apart and reconstructing
|
56
|
+
YAML files.
|
57
|
+
created: '2011-10-22'
|
58
|
+
date: '2012-12-12'
|
data/HISTORY.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# RELEASE HISTORY
|
2
|
+
|
3
|
+
## 0.1.0 / 2012-12-12
|
4
|
+
|
5
|
+
The project has been renamed `yaml-command` instead of the
|
6
|
+
abbreviated `yc`. Makes it more obvious what the project is
|
7
|
+
about.
|
8
|
+
|
9
|
+
Changes:
|
10
|
+
|
11
|
+
* Fix missing output of `splat`.
|
12
|
+
* Fix yaml output of `get` command.
|
13
|
+
* Add manpages for all commands.
|
14
|
+
|
15
|
+
|
16
|
+
## 0.0.1 / 2012-03-18
|
17
|
+
|
18
|
+
This is the initial public release of YC.
|
19
|
+
|
20
|
+
Changes:
|
21
|
+
|
22
|
+
* Happy First Release Day!
|
23
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
YC - YAML Command
|
2
|
+
|
3
|
+
Copyright (c) 2011 Rubyworks. All rights reserved
|
4
|
+
|
5
|
+
Licensed (spdx) BSD-2-Clause
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without modification, are
|
8
|
+
permitted provided that the following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this list of
|
11
|
+
conditions and the following disclaimer.
|
12
|
+
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list
|
14
|
+
of conditions and the following disclaimer in the documentation and/or other materials
|
15
|
+
provided with the distribution.
|
16
|
+
|
17
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
18
|
+
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
19
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
23
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
25
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
|
27
|
+
(http://rubyworks.github.com/yc)
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# YAML COMMAND
|
2
|
+
|
3
|
+
[Website](http://rubyworks.github.com/yaml_command) /
|
4
|
+
[Report Issue](http://github.com/rubyworks/yaml_command/issues) /
|
5
|
+
[Development](http://github.com/rubyworks/yaml_command) /
|
6
|
+
[IRC Channel](irc://chat.us.freenode.net/rubyworks)
|
7
|
+
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
YAML Command is a command line tool for working with YAML files.
|
12
|
+
|
13
|
+
While currently a work in progress, the goal is evolve the design
|
14
|
+
for a standardized `yaml` command line tool. While this early
|
15
|
+
implementation is written in Ruby, ultimately the final version
|
16
|
+
would be written in C and be widely available.
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Commands are invoked on the command line with:
|
21
|
+
|
22
|
+
$ yaml <command> [options...] [arguments...]
|
23
|
+
|
24
|
+
### Commands
|
25
|
+
|
26
|
+
The following commands are currently supported:
|
27
|
+
|
28
|
+
* **get** <br/>
|
29
|
+
The `get` command simply extracts a portion of a YAML file and outputs
|
30
|
+
it to stdout.
|
31
|
+
|
32
|
+
* **set** <br/>
|
33
|
+
The `set` commnd is the opposite of `get` in that it lets you change
|
34
|
+
a portion of a YAML file. By defult the changed YAML document will go
|
35
|
+
to stdout, using the `-s/--save` option rewrites the file with the change.
|
36
|
+
|
37
|
+
* **sort** <br/>
|
38
|
+
The `sort` command can be used to sort portions of a YAML document.
|
39
|
+
|
40
|
+
* **slurp** <br/>
|
41
|
+
The `slurp` command takes a directory and converts it's contents into a YAML file.
|
42
|
+
|
43
|
+
* **splat** <br/>
|
44
|
+
The `splat` command take a YAML file and converts it into a file directory structure.
|
45
|
+
It is essentially the opposite of slurp.
|
46
|
+
|
47
|
+
* **edit** <br/>
|
48
|
+
Edit will open a YAML file for editing in the default editor (as defined by
|
49
|
+
$EDITOR), and allow you to edit it.
|
50
|
+
|
51
|
+
If instead you edit a directory, then the directory will be automatically
|
52
|
+
slurped into a temporary file. After editing the temporary file will be
|
53
|
+
splatted back out to update the directory and it's files.
|
54
|
+
|
55
|
+
* **view** <br/>
|
56
|
+
Outputs a colorized rendering of the YAML file.
|
57
|
+
|
58
|
+
### Options
|
59
|
+
|
60
|
+
Some commands has special options. Use `yaml <command> --help` to learn about those.
|
61
|
+
All (or nearly all) commands support the following options.
|
62
|
+
|
63
|
+
* **-F** / **--file [PATH]** <br/>
|
64
|
+
Use the given YAML file instead of using stdin.
|
65
|
+
|
66
|
+
* **-y** / **--yaml** <br/>
|
67
|
+
Output results in YAML format.
|
68
|
+
|
69
|
+
* **-j** / **--json** <br/>
|
70
|
+
Output results in JSON format.
|
71
|
+
|
72
|
+
* **-m** / **--mute** <br/>
|
73
|
+
Surpress all output.
|
74
|
+
|
75
|
+
* **-f** / **--force** <br/>
|
76
|
+
Used to force overwrites when necessary.
|
77
|
+
|
78
|
+
* **--debug** <br/>
|
79
|
+
Turn on debug mode to get detailed error report if there is a problem.
|
80
|
+
|
81
|
+
|
82
|
+
## Requirements
|
83
|
+
|
84
|
+
* [Executable](http://rubyworks.github.com/executable) library handle CLI parsing.
|
85
|
+
* [ANSI](http://rubyworks.github.com/ansi) library provides console colorization.
|
86
|
+
|
87
|
+
|
88
|
+
## Copyrights
|
89
|
+
|
90
|
+
Copyright (c) 2011 Rubyworks. All rights reserved.
|
91
|
+
|
92
|
+
YAML Comamnd may be distributed in accordance with the **BSD-2-Clause** license.
|
93
|
+
|
94
|
+
See the LICENSE.txt file for details.
|
data/bin/yaml
ADDED
data/lib/yaml_command.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'executable'
|
4
|
+
require 'yaml_command/base'
|
5
|
+
require 'yaml_command/get'
|
6
|
+
require 'yaml_command/set'
|
7
|
+
require 'yaml_command/sort'
|
8
|
+
require 'yaml_command/splat'
|
9
|
+
require 'yaml_command/slurp'
|
10
|
+
require 'yaml_command/edit'
|
11
|
+
require 'yaml_command/view'
|
12
|
+
|
13
|
+
module YAMLCommand
|
14
|
+
|
15
|
+
#
|
16
|
+
module Console
|
17
|
+
extend self
|
18
|
+
|
19
|
+
#
|
20
|
+
def slurp(dir, options={})
|
21
|
+
slurp = SlurpCommand.new(options)
|
22
|
+
slurp.call(dir)
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
def splat(file, options={})
|
27
|
+
splat = SplatCommand.new(options)
|
28
|
+
splat.call(file)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
def self.const_missing(name)
|
35
|
+
index[name.to_s.downcase] || super(name)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
def self.index
|
40
|
+
@index ||= begin
|
41
|
+
file = File.dirname(__FILE__) + '/yaml_command.yml'
|
42
|
+
YAML.load_file(file)
|
43
|
+
rescue
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
type: ruby
|
3
|
+
revision: 2013
|
4
|
+
sources:
|
5
|
+
- Index.yml
|
6
|
+
authors:
|
7
|
+
- name: Thomas Sawyer
|
8
|
+
email: transfire@gmail.com
|
9
|
+
organizations:
|
10
|
+
- name: Rubyworks
|
11
|
+
requirements:
|
12
|
+
- name: ansi
|
13
|
+
- name: executable
|
14
|
+
- groups:
|
15
|
+
- build
|
16
|
+
development: true
|
17
|
+
name: detroit
|
18
|
+
- groups:
|
19
|
+
- test
|
20
|
+
development: true
|
21
|
+
name: qed
|
22
|
+
conflicts: []
|
23
|
+
alternatives: []
|
24
|
+
resources:
|
25
|
+
- type: home
|
26
|
+
uri: http://rubyworks.github.com/yaml_command
|
27
|
+
label: Homepage
|
28
|
+
- type: code
|
29
|
+
uri: http://github.com/rubyworks/yaml_command
|
30
|
+
label: Source Code
|
31
|
+
- type: bugs
|
32
|
+
uri: http://github.com/rubyworks/yaml_command/issues
|
33
|
+
label: Issue Tracker
|
34
|
+
- type: mail
|
35
|
+
uri: http://groups.google.com/rubyworks-mailinglist
|
36
|
+
label: Mailing List
|
37
|
+
- type: chat
|
38
|
+
uri: irc://chat.us.freenode.net/rubyworks
|
39
|
+
label: IRC Channel
|
40
|
+
repositories:
|
41
|
+
- name: upstream
|
42
|
+
scm: git
|
43
|
+
uri: git://github.com/rubyworks/yaml_command.git
|
44
|
+
categories: []
|
45
|
+
load_path:
|
46
|
+
- lib
|
47
|
+
copyrights:
|
48
|
+
- holder: RubyWorks
|
49
|
+
year: '2011'
|
50
|
+
license: BSD-2-Clause
|
51
|
+
name: yaml_command
|
52
|
+
title: YAML Command
|
53
|
+
version: 0.1.0
|
54
|
+
summary: Command-line access to YAML files.
|
55
|
+
description: YAML Command provides a command line interface to teasing apart and reconstructing
|
56
|
+
YAML files.
|
57
|
+
created: '2011-10-22'
|
58
|
+
date: '2012-12-12'
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module YAMLCommand
|
2
|
+
|
3
|
+
# Abstract base command that all others use.
|
4
|
+
#
|
5
|
+
class Command < Executable::Command
|
6
|
+
|
7
|
+
#
|
8
|
+
def self.command_name
|
9
|
+
'yaml'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Debug mode.
|
13
|
+
def debug=(boolean)
|
14
|
+
$DEBUG = boolean ? true : false
|
15
|
+
end
|
16
|
+
|
17
|
+
# Debug mode.
|
18
|
+
def debug?
|
19
|
+
$DEBUG
|
20
|
+
end
|
21
|
+
|
22
|
+
# Force file overwrites.
|
23
|
+
attr_switch :force
|
24
|
+
alias_switch :f, :force
|
25
|
+
|
26
|
+
# YAML file to use as data source.
|
27
|
+
# This can be used as an alternative to `$stdin`.
|
28
|
+
attr_accessor :file
|
29
|
+
alias_accessor :F, :file
|
30
|
+
|
31
|
+
# Output using Ruby's #inspect method.
|
32
|
+
def inspect=(boolean)
|
33
|
+
@format = :inspect if boolean
|
34
|
+
end
|
35
|
+
|
36
|
+
# Output using Ruby's #inspect method.
|
37
|
+
def inspect?
|
38
|
+
@format == :inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
# Output using #to_yaml.
|
42
|
+
def yaml=(boolean)
|
43
|
+
@format = :yaml if boolean
|
44
|
+
end
|
45
|
+
|
46
|
+
# Output using #to_yaml.
|
47
|
+
def yaml?
|
48
|
+
@format == :yaml
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_switch :y, :yaml
|
52
|
+
|
53
|
+
# Output using #to_json.
|
54
|
+
def json=(boolean)
|
55
|
+
@format = :json if boolean
|
56
|
+
end
|
57
|
+
|
58
|
+
# Output using #to_json.
|
59
|
+
def json?
|
60
|
+
@format == :json
|
61
|
+
end
|
62
|
+
|
63
|
+
alias_switch :j, :json
|
64
|
+
|
65
|
+
# Surpress all output.
|
66
|
+
def mute?
|
67
|
+
@format == :mute
|
68
|
+
end
|
69
|
+
|
70
|
+
# Surpress all output.
|
71
|
+
def mute=(boolean)
|
72
|
+
@format = :mute if boolean
|
73
|
+
end
|
74
|
+
|
75
|
+
alias_switch :m, :mute
|
76
|
+
|
77
|
+
# Show detailed help message.
|
78
|
+
def help!
|
79
|
+
cli.show_help
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
|
83
|
+
# Show minimal help message.
|
84
|
+
def h!
|
85
|
+
puts cli
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
|
89
|
+
# YAML Command Language
|
90
|
+
def call
|
91
|
+
if file
|
92
|
+
output(data)
|
93
|
+
else
|
94
|
+
puts cli
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
#protected
|
99
|
+
|
100
|
+
#
|
101
|
+
def data=(data)
|
102
|
+
@data = data
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
attr_reader :format
|
108
|
+
|
109
|
+
#
|
110
|
+
def data
|
111
|
+
@data ||= (
|
112
|
+
if file
|
113
|
+
YAML.load_file(file)
|
114
|
+
else
|
115
|
+
YAML.load($stdin)
|
116
|
+
end
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
def output(result)
|
122
|
+
case format
|
123
|
+
when :yaml
|
124
|
+
puts result.to_yaml
|
125
|
+
when :json
|
126
|
+
require 'json'
|
127
|
+
puts result.to_json
|
128
|
+
when :inspect
|
129
|
+
puts result.inspect
|
130
|
+
when :mute
|
131
|
+
# no output
|
132
|
+
else
|
133
|
+
puts result
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|