versacommerce-cli 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f3e6de1645b8f340f9e406ba0bb2d3af03f5eb2
4
- data.tar.gz: 877c844cd21384c804a9c3a98cad9416dbe488ac
3
+ metadata.gz: 2d406d69a4c3edfc46aed178072f09d4f6f15ff2
4
+ data.tar.gz: 50c63b0f2c811802d64bee8354808ef99a21f1ea
5
5
  SHA512:
6
- metadata.gz: 23117f428585c826764f558529fcd54d925907092bc97fb92652f353094fd074bcf9c57ef4ef55b3f83d8f33e9d8236901456fdfc453363bcb11ac4cded20ed8
7
- data.tar.gz: afba1ddf5d4f2eb0472c665d024d486eebf1ef2422d8209f371812cdf4b714b9beb6467242fd1f6d49d5e52f349097d348dc1847eb4fd8eeeab92413079b6ec8
6
+ metadata.gz: 8bfd8d6858b041869680204b7332c912329e1ea87f45476331ea9ac252e4aca7f1de72f90ffe134b4ec3470abc4db4d2cc273cefbbc63103c155cbab4959986b
7
+ data.tar.gz: 21b4bb8417551983df2d7399c1966708a58e9e37d4b790a338496038446ceb89ca89de2c8122d63193dd35b19eed9ae02dec9c8728a52d583f6af47a585163fb
data/README.md CHANGED
@@ -18,6 +18,8 @@ $ gem install versacommerce-cli
18
18
 
19
19
  ### `vc-theme`
20
20
 
21
+ #### Authorization
22
+
21
23
  The `vc-theme` command has several subcommands that all need an Authorization in order to work. You can get such an Authorization from your shop's admin section.
22
24
 
23
25
  There are 4 ways to provide an Authorization to the CLI, which are checked in order:
@@ -43,15 +45,32 @@ authorization: YOUR_AUTHORIZATION
43
45
  ```
44
46
 
45
47
  3.
48
+ Provide an implicit config file in the working directory: Same as 2, but the config file location is fix to the working directory.
49
+
50
+ 4.
46
51
  Provide a `THEME_AUTHORIZATION` environment variable:
47
52
 
48
53
  ```sh
49
54
  THEME_AUTHORIZATION=YOUR_AUTHORIZATION vc-theme <subcommand>
50
55
  ```
51
56
 
52
- 4.
57
+ 5.
53
58
  Provide an implicit config file. Same as 2, but the config file location is fix to `~/.config/versacommerce/cli/config.yml`.
54
59
 
60
+ #### Quicksaving Authorization
61
+
62
+ You can quicksave the given authorization (from any source) to a config.yml file inside the working directory using the --save-config command line option:
63
+
64
+ ```sh
65
+ $ vc-theme <subcommand> --save-config
66
+ ```
67
+
68
+ It's also possible to change the path the config.yml file is saved to:
69
+
70
+ ```sh
71
+ $ vc-theme <subcommand> --save-config=path/to/directory
72
+ ```
73
+
55
74
  The following subcommands are available:
56
75
 
57
76
  #### `vc-theme download`
@@ -72,7 +91,7 @@ The directory will be created by using `mkdir -p`, so you don't need to worry ab
72
91
 
73
92
  #### `vc-theme watch`
74
93
 
75
- The `vc-theme watch` subcommand is used to synchronize local files to the Theme API. Usage:
94
+ The `vc-theme watch` subcommand is used to synchronize local files with the Theme API. Usage:
76
95
 
77
96
  ```sh
78
97
  $ vc-theme watch
@@ -84,6 +103,20 @@ This will watch for file changes made in (and below) the working directory. When
84
103
  $ vc-theme watch --path=path/to/directory
85
104
  ```
86
105
 
106
+ #### `vc-theme upload`
107
+
108
+ The `vc-theme upload` subcommand is used to push a directory to the Theme API. Usage:
109
+
110
+ ```sh
111
+ $ vc-theme upload
112
+ ```
113
+
114
+ This will upload the working directory and its descendants to the Theme API. For each file found under the working directory the upload process will try to delete and readd the file to the Theme API. If you want to change the path that is being uploaded, provide a `path` command line option:
115
+
116
+ ```sh
117
+ $ vc-theme upload --path=path/to/directory
118
+ ```
119
+
87
120
  ## Development
88
121
 
89
122
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -30,8 +30,10 @@ module Versacommerce
30
30
  private
31
31
 
32
32
  def write(*messages)
33
+ time = Time.now.strftime('%F %R')
34
+
33
35
  messages.each do |message|
34
- puts '-- %s' % message
36
+ puts '[%s] -- %s' % [time, message]
35
37
  end
36
38
  end
37
39
  end
@@ -11,14 +11,16 @@ require 'versacommerce/theme_api_client'
11
11
  module Versacommerce
12
12
  module CLI
13
13
  class Theme < Thor
14
- class_option :authorization
15
- class_option :config
16
- class_option :verbose, type: :boolean
14
+ class_option :authorization, aliases: :a
15
+ class_option :config, banner: 'CONFIG_PATH', aliases: :c
16
+ class_option :verbose, type: :boolean, aliases: :v
17
+ class_option :save_config, banner: 'CONFIG_PATH', aliases: :s
17
18
 
18
19
  desc 'download', 'Downloads a complete Theme from the Theme API.'
19
20
  option :path, default: Pathname.pwd.join('theme')
20
21
  def download
21
22
  ensure_authorization!
23
+ save_config
22
24
 
23
25
  path = Pathname.new(options[:path]).expand_path
24
26
  logger.info('Downloading Theme to %s' % path)
@@ -37,7 +39,12 @@ module Versacommerce
37
39
  desc 'watch', 'Watches a directory and pushes file changes to the Theme API.'
38
40
  option :path, default: Pathname.pwd
39
41
  def watch
42
+ ensure_authorization!
43
+ save_config
44
+
40
45
  theme_path = Pathname.new(options[:path]).expand_path
46
+ validate_path!(theme_path)
47
+
41
48
  logger.info 'Watching %s' % theme_path
42
49
 
43
50
  listener = Listen.to(theme_path) do |modified, added, removed|
@@ -49,11 +56,27 @@ module Versacommerce
49
56
  end
50
57
  end
51
58
 
52
- listener.start
53
- sleep
54
- rescue SystemExit, Interrupt
55
- logger.info('Stopped watching')
56
- exit
59
+ begin
60
+ listener.start
61
+ sleep
62
+ rescue SystemExit, Interrupt
63
+ logger.info('Stopped watching')
64
+ exit
65
+ end
66
+ end
67
+
68
+ desc 'upload', 'Uploads a directory and its descendants to the Theme API.'
69
+ option :path, default: Pathname.pwd
70
+ def upload
71
+ ensure_authorization!
72
+ save_config
73
+
74
+ theme_path = Pathname.new(options[:path]).expand_path
75
+ validate_path!(theme_path)
76
+
77
+ logger.info 'Uploading %s' % theme_path
78
+ add_directory(theme_path, theme_path)
79
+ logger.success('Uploaded %s' % theme_path)
57
80
  end
58
81
 
59
82
  private
@@ -83,25 +106,67 @@ module Versacommerce
83
106
  rescue Versacommerce::ThemeAPIClient::Fetcher::RecordNotFoundError
84
107
  end
85
108
 
109
+ def add_directory(theme_path, path)
110
+ path.children.each do |child|
111
+ case child.ftype
112
+ when 'file'
113
+ delete_file(theme_path, child)
114
+ add_file(theme_path, child)
115
+ when 'directory'
116
+ add_directory(theme_path, child)
117
+ end
118
+ end
119
+ end
120
+
86
121
  def client
87
122
  @client ||= ThemeAPIClient.new(authorization: authorization)
88
123
  end
89
124
 
125
+ def save_config
126
+ if config = options[:save_config]
127
+ path = case config
128
+ when 'save_config'
129
+ Pathname.pwd.expand_path
130
+ else
131
+ Pathname.new(config).expand_path
132
+ end
133
+
134
+ validate_path!(path)
135
+ yaml = {'authorization' => authorization}.to_yaml
136
+ File.write(path.join('config.yml'), yaml)
137
+ logger.debug('Saved config.yml to %s' % path)
138
+ end
139
+ end
140
+
90
141
  def ensure_authorization!
91
142
  unless authorization
92
- puts 'Could not find authorization.'
143
+ logger.error('Could not find authorization.')
144
+ exit 1
145
+ end
146
+ end
147
+
148
+ def validate_path!(path)
149
+ unless path.directory?
150
+ logger.error('%s is not a directory.' % path)
93
151
  exit 1
94
152
  end
95
153
  end
96
154
 
97
155
  def authorization
98
- options[:authorization] || explicit_config['authorization'] || ENV['THEME_AUTHORIZATION'] || implicit_config['authorization']
156
+ options[:authorization] || explicit_config['authorization'] || implicit_pwd_config['authorization'] || ENV['THEME_AUTHORIZATION'] || implicit_config['authorization']
99
157
  end
100
158
 
101
159
  def explicit_config
102
160
  @explicit_config ||= options[:config] ? YAML.load_file(options[:config]) : {}
103
161
  end
104
162
 
163
+ def implicit_pwd_config
164
+ @implicit_pwd_config ||= begin
165
+ config = Pathname.pwd.join('config.yml').expand_path
166
+ config.file? ? YAML.load_file(config) : {}
167
+ end
168
+ end
169
+
105
170
  def implicit_config
106
171
  @implicit_config ||= begin
107
172
  config = Pathname.new('~/.config/versacommerce/cli/config.yml').expand_path
@@ -1,5 +1,5 @@
1
1
  module Versacommerce
2
2
  module CLI
3
- VERSION = Gem::Version.new('0.1.0')
3
+ VERSION = Gem::Version.new('0.2.0')
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: versacommerce-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Bühlmann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor