csv_plus_plus 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +103 -0
- data/bin/csv++ +83 -0
- data/lib/csv_plus_plus/version.rb +1 -1
- metadata +95 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11364af3824cbfff63df10d7b932a6ad2c7a222e1a40b39f151af82a150d5dc4
|
4
|
+
data.tar.gz: 2d6fe31ae0e6a7dee0c19f31b0328e1b20973541c6e2c12cb64f3fbf96d8fa02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 623953f6ff728e1dfc1f7f329dbc89e5ae7b7687cebd6da387ea36f0b0659020142e5f2029533e46964b8bf51c2f78b79634b9bb346cad6e6c96ae69d6737fb1
|
7
|
+
data.tar.gz: 0604bc094e8d287bcec1390ff884786fe8dbf12b5e6e4ec4785cc9cef2297f92360a9a60809c855630edd5f633b2bc16bf378cb0c47a1be7eb2a7f70ae6beb7a
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
[](https://rubystyle.guide)
|
2
|
+
|
3
|
+
# csv++
|
4
|
+
|
5
|
+
A tool that allows you to programatically author spreadsheets in your favorite text editor and write their results to CSV, Google Sheets, Excel and other spreadsheet formats. This allows you to write a spreadsheet template, check it into git and push changes out to spreadsheets using typical dev tools.
|
6
|
+
|
7
|
+
## Template Language
|
8
|
+
|
9
|
+
A `csvpp` file consists of a (optional) code section and a CSV section separated by `---`. In the code section you can define variables and functions that can be used in the CSV below it. For example:
|
10
|
+
|
11
|
+
```
|
12
|
+
fees := 0.65 # my broker charges $0.65 a trade
|
13
|
+
|
14
|
+
price := cellref(C)
|
15
|
+
quantity := cellref(D)
|
16
|
+
|
17
|
+
def profit() (price * quantity) - fees
|
18
|
+
|
19
|
+
---
|
20
|
+
![[format=bold/align=center]]Date,Ticker,Price,Quantity,Total,Fees
|
21
|
+
![[expand]],[[format=bold]],,,"=PROFIT()",$$fees
|
22
|
+
```
|
23
|
+
|
24
|
+
## Predefined Variables
|
25
|
+
|
26
|
+
* `$$rownum` - The current row number. The first row of the spreadsheet starts at 1
|
27
|
+
|
28
|
+
## Predefined Functions
|
29
|
+
|
30
|
+
* `cellref(CELL)` - Returns a reference to the `CELL` relative to the current row. If the current `$$rownum` is `2`, then `CELLREF("C")` returns a reference to cell `C2`.
|
31
|
+
|
32
|
+
## Modifiers
|
33
|
+
|
34
|
+
Modifiers can change the formatting of a cell or row, apply validation, change alignment, etc. All of the normal rules of CSV apply, with the addition that each cell can have modifiers (specified in `[[`/`]]` for cells and `![[`/`]]` for rows):
|
35
|
+
|
36
|
+
```
|
37
|
+
foo,[[...]]bar,baz
|
38
|
+
```
|
39
|
+
|
40
|
+
specifying formatting or various other modifiers to the cell. Additionally a row can start with:
|
41
|
+
|
42
|
+
```
|
43
|
+
![[...]]foo,bar,baz
|
44
|
+
```
|
45
|
+
|
46
|
+
which will apply that modifier to all cells in the row.
|
47
|
+
|
48
|
+
### Examples
|
49
|
+
|
50
|
+
* Align the second cell left, align the last cell to the center and make it bold and italicized:
|
51
|
+
|
52
|
+
```
|
53
|
+
Date,[[align=left]]Amount,Quantity,[[align=center/format=bold italic]]Price
|
54
|
+
```
|
55
|
+
|
56
|
+
* Underline and center-align an entire row:
|
57
|
+
|
58
|
+
```
|
59
|
+
![[align=center/format=underline]]Date,Amount,Quantity,Price
|
60
|
+
```
|
61
|
+
|
62
|
+
* A header for the first row, then some formulas that repeat for each row for the rest of the spreadsheet:
|
63
|
+
|
64
|
+
```
|
65
|
+
![[align=center/format=bold]]Date,Price,Quantity,Profit
|
66
|
+
![[expand=1:]],,,"=MULTIPLY(cellref(B), cellref(C))"
|
67
|
+
```
|
68
|
+
|
69
|
+
## Setup (Google Sheets)
|
70
|
+
|
71
|
+
Just install it via rubygems (homebrew and debian packages are in the works):
|
72
|
+
|
73
|
+
`$ gem install csv_plus_plus`
|
74
|
+
|
75
|
+
### Publishing to Google Sheets
|
76
|
+
|
77
|
+
* Go to the [GCP developers console](https://console.cloud.google.com/projectselector2/apis/credentials?pli=1&supportedpurview=project), create a service account and export keys for it to `~/.config/gcloud/application_default_credentials.json`
|
78
|
+
* "Share" the spreadsheet with the email associated with the service account
|
79
|
+
|
80
|
+
## CLI Arguments
|
81
|
+
|
82
|
+
```
|
83
|
+
Usage: csv++ [options]
|
84
|
+
-b, --backup Create a backup of the spreadsheet before applying changes.
|
85
|
+
-g, --google-sheet-id SHEET_ID The id of the sheet - you can extract this from the URL: https://docs.google.com/spreadsheets/d/< ... SHEET_ID ... >/edit#gid=0
|
86
|
+
-c, --create Create the sheet if it doesn't exist. It will use --sheet-name if specified
|
87
|
+
-k, --key-values KEY_VALUES A comma-separated list of key=values which will be made available to the template
|
88
|
+
-n, --sheet-name SHEET_NAME The name of the sheet to apply the template to
|
89
|
+
-v, --verbose Enable verbose output
|
90
|
+
-x, --offset-columns OFFSET Apply the template offset by OFFSET cells
|
91
|
+
-y, --offset-rows OFFSET Apply the template offset by OFFSET rows
|
92
|
+
-h, --help Show help information
|
93
|
+
```
|
94
|
+
|
95
|
+
## Usage Examples
|
96
|
+
|
97
|
+
```
|
98
|
+
# apply my_taxes_template.csvpp to an existing Google Sheet with name "Taxes 2022"
|
99
|
+
$ csv++ --sheet-name "Taxes 2022" --sheet-id "[...]" my_taxes_template.csvpp
|
100
|
+
|
101
|
+
# take input from stdin, supply a variable ($$rate = 1) and apply to the "Stocks" spreadsheet
|
102
|
+
$ cat stocks.csvpp | csv++ -k "rate=1" -n "Stocks" -i "[...]"
|
103
|
+
```
|
data/bin/csv++
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require_relative '../lib/csv_plus_plus'
|
6
|
+
|
7
|
+
options = ::CSVPlusPlus::Options.new
|
8
|
+
|
9
|
+
option_parser =
|
10
|
+
# rubocop:disable Metrics/BlockLength
|
11
|
+
::OptionParser.new do |parser|
|
12
|
+
parser.on('-b', '--backup', 'Create a backup of the spreadsheet before applying changes.') do
|
13
|
+
options.backup = true
|
14
|
+
end
|
15
|
+
|
16
|
+
parser.on(
|
17
|
+
'-g SHEET_ID',
|
18
|
+
'--google-sheet-id SHEET_ID',
|
19
|
+
'The id of the sheet - you can extract this from the URL: ' \
|
20
|
+
'https://docs.google.com/spreadsheets/d/< ... SHEET_ID ... >/edit#gid=0'
|
21
|
+
) do |v|
|
22
|
+
options.google_sheet_id = v
|
23
|
+
end
|
24
|
+
|
25
|
+
parser.on('-c', '--create', "Create the sheet if it doesn't exist. It will use --sheet-name if specified") do
|
26
|
+
options.create_if_not_exists = true
|
27
|
+
end
|
28
|
+
|
29
|
+
parser.on(
|
30
|
+
'-k KEY_VALUES',
|
31
|
+
'--key-values KEY_VALUES',
|
32
|
+
'A comma-separated list of key=values which will be made available to the template'
|
33
|
+
) do |v|
|
34
|
+
options.key_values =
|
35
|
+
begin
|
36
|
+
[v.split('=')].to_h
|
37
|
+
rescue ::StandardError
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
parser.on('-n SHEET_NAME', '--sheet-name SHEET_NAME', 'The name of the sheet to apply the template to') do |v|
|
43
|
+
options.sheet_name = v
|
44
|
+
end
|
45
|
+
|
46
|
+
parser.on('-o OUTPUT_FILE', '--output OUTPUT_FILE', 'The file to write to (must be .csv, .ods, .xls)') do |v|
|
47
|
+
options.output_filename = v
|
48
|
+
end
|
49
|
+
|
50
|
+
parser.on('-v', '--verbose', 'Enable verbose output') do
|
51
|
+
options.verbose = true
|
52
|
+
end
|
53
|
+
|
54
|
+
parser.on('-x OFFSET', '--offset-columns OFFSET', 'Apply the template offset by OFFSET cells') do |v|
|
55
|
+
options.offset[0] = v
|
56
|
+
end
|
57
|
+
|
58
|
+
parser.on('-y OFFSET', '--offset-rows OFFSET', 'Apply the template offset by OFFSET rows') do |v|
|
59
|
+
options.offset[1] = v
|
60
|
+
end
|
61
|
+
|
62
|
+
parser.on('-h', '--help', 'Show help information') do
|
63
|
+
puts(parser)
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
end
|
67
|
+
# rubocop:enable Metrics/BlockLength
|
68
|
+
|
69
|
+
option_parser.parse!
|
70
|
+
|
71
|
+
error_message = options.validate
|
72
|
+
unless error_message.nil?
|
73
|
+
warn(error_message)
|
74
|
+
puts(option_parser)
|
75
|
+
exit(1)
|
76
|
+
end
|
77
|
+
|
78
|
+
begin
|
79
|
+
::CSVPlusPlus.apply_template_to_sheet!(::ARGF.read, ::ARGF.filename, options)
|
80
|
+
rescue ::CSVPlusPlus::Language::SyntaxError => e
|
81
|
+
warn(options.verbose ? e.to_verbose_trace : e.to_trace)
|
82
|
+
exit(1)
|
83
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_plus_plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Carroll
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-apis-sheets_v4
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: googleauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: solargraph
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: "A programming language built on top of CSV. You can define functions
|
98
|
+
and variables to use in your spreadsheet, \nthen compile it to Excel, CSV, Google
|
99
|
+
Sheets, etc.\n"
|
14
100
|
email: patrick@patrickomatic.com
|
15
|
-
executables:
|
101
|
+
executables:
|
102
|
+
- csv++
|
16
103
|
extensions: []
|
17
104
|
extra_rdoc_files: []
|
18
105
|
files:
|
106
|
+
- CHANGELOG.md
|
107
|
+
- README.md
|
108
|
+
- bin/csv++
|
19
109
|
- lib/csv_plus_plus.rb
|
20
110
|
- lib/csv_plus_plus/cell.rb
|
21
111
|
- lib/csv_plus_plus/code_section.rb
|