Skip to content

Commit

Permalink
enable to use config (#16)
Browse files Browse the repository at this point in the history
* enable to use config

* use commonized option
  • Loading branch information
kogai authored Dec 3, 2020
1 parent 9f5dce6 commit 287e35e
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ deploy/theme:

deploy/contents: $(MD_FILES)
$(BZL) run //content/cmd/content -- deploy \
--input $(PWD)/contents \
--dir $(PWD)/contents \
--domain k9books.myshopify.com \
--key $(MARKDOWN_APP_KEY) \
--secret $(MARKDOWN_APP_SECRET) \
--token $(MARKDOWN_APP_SECRET)

download/contents: $(MD_FILES)
$(BZL) run //content/cmd/content -- download \
--output $(PWD)/contents \
--dir $(PWD)/contents \
--domain k9books.myshopify.com \
--key $(MARKDOWN_APP_KEY) \
--secret $(MARKDOWN_APP_SECRET) \
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,8 @@ go_repository(
go_repository(
name = "in_gopkg_yaml_v2",
importpath = "gopkg.in/yaml.v2",
sum = "h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=",
version = "v2.3.0",
sum = "h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=",
version = "v2.4.0",
)

go_repository(
Expand Down
6 changes: 6 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ development:
password: ${THEME_APP_SECRET}
theme_id: ${THEME_ID}
store: k9books.myshopify.com
content:
domain: k9books.myshopify.com
key: ${MARKDOWN_APP_KEY}
secret: ${MARKDOWN_APP_SECRET}
token: ${MARKDOWN_APP_SECRET}
dir: ${PWD}/contents
1 change: 1 addition & 0 deletions content/cmd/content/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ go_library(
deps = [
"//content:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@in_gopkg_yaml_v2//:go_default_library",
],
)

Expand Down
124 changes: 112 additions & 12 deletions content/cmd/content/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"

"github.com/kogai/k9bookshelf/content"

"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
)

var rootCmd = &cobra.Command{
Expand All @@ -18,15 +20,68 @@ var rootCmd = &cobra.Command{
},
}

type configTy struct {
Content struct {
Domain *string `yaml:"domain,omitempty"`
Key *string `yaml:"key,omitempty"`
Secret *string `yaml:"secret,omitempty"`
Token *string `yaml:"token,omitempty"`
Dir *string `yaml:"dir,omitempty"`
} `yaml:"content,omitempty"`
}

var deployCmd = &cobra.Command{
Use: "deploy",
Short: "Upload contents to store",
Run: func(cmd *cobra.Command, args []string) {
input := cmd.Flag("input").Value.String()
shopDomain := cmd.Flag("domain").Value.String()
appKey := cmd.Flag("key").Value.String()
appSecret := cmd.Flag("secret").Value.String()
shopToken := cmd.Flag("token").Value.String()
var input, shopDomain, appKey, appSecret, shopToken string

config := cmd.Flag("config").Value.String()
if config != "" {
buf, err := ioutil.ReadFile(config)
if err != nil {
log.Fatalln(err)
}
expanded := os.ExpandEnv(string(buf))
var conf configTy
err = yaml.Unmarshal([]byte(expanded), &conf)
if err != nil {
log.Fatalln(err)
}

if conf.Content.Domain != nil {
shopDomain = *conf.Content.Domain
} else {
shopDomain = cmd.Flag("domain").Value.String()
}
if conf.Content.Key != nil {
appKey = *conf.Content.Key
} else {
appKey = cmd.Flag("key").Value.String()
}
if conf.Content.Secret != nil {
appSecret = *conf.Content.Secret
} else {
appSecret = cmd.Flag("secret").Value.String()
}
if conf.Content.Token != nil {
shopToken = *conf.Content.Token
} else {
shopToken = cmd.Flag("token").Value.String()
}
if conf.Content.Dir != nil {
input = *conf.Content.Dir
} else {
input = cmd.Flag("dir").Value.String()
}
} else {
shopDomain = cmd.Flag("domain").Value.String()
appKey = cmd.Flag("key").Value.String()
appSecret = cmd.Flag("secret").Value.String()
shopToken = cmd.Flag("token").Value.String()
input = cmd.Flag("dir").Value.String()
}

if shopDomain == "" || appKey == "" || appSecret == "" || shopToken == "" {
log.Fatalln(fmt.Sprintf("One of required parameter is empty, shopDomain='%s' appKey='%s' appSecret='%s' shopToken='%s'", shopDomain, appKey, appSecret, shopToken))
}
Expand All @@ -41,11 +96,54 @@ var downloadCmd = &cobra.Command{
Use: "download",
Short: "Download contents from store",
Run: func(cmd *cobra.Command, args []string) {
output := cmd.Flag("output").Value.String()
shopDomain := cmd.Flag("domain").Value.String()
appKey := cmd.Flag("key").Value.String()
appSecret := cmd.Flag("secret").Value.String()
shopToken := cmd.Flag("token").Value.String()
var output, shopDomain, appKey, appSecret, shopToken string

config := cmd.Flag("config").Value.String()
if config != "" {
buf, err := ioutil.ReadFile(config)
if err != nil {
log.Fatalln(err)
}
expanded := os.ExpandEnv(string(buf))
var conf configTy
err = yaml.Unmarshal([]byte(expanded), &conf)
if err != nil {
log.Fatalln(err)
}

if conf.Content.Domain != nil {
shopDomain = *conf.Content.Domain
} else {
shopDomain = cmd.Flag("domain").Value.String()
}
if conf.Content.Key != nil {
appKey = *conf.Content.Key
} else {
appKey = cmd.Flag("key").Value.String()
}
if conf.Content.Secret != nil {
appSecret = *conf.Content.Secret
} else {
appSecret = cmd.Flag("secret").Value.String()
}
if conf.Content.Token != nil {
shopToken = *conf.Content.Token
} else {
shopToken = cmd.Flag("token").Value.String()
}
if conf.Content.Dir != nil {
output = *conf.Content.Dir
} else {
output = cmd.Flag("dir").Value.String()
}
} else {
shopDomain = cmd.Flag("domain").Value.String()
appKey = cmd.Flag("key").Value.String()
appSecret = cmd.Flag("secret").Value.String()
shopToken = cmd.Flag("token").Value.String()
output = cmd.Flag("dir").Value.String()
}

if shopDomain == "" || appKey == "" || appSecret == "" || shopToken == "" {
log.Fatalln(fmt.Sprintf("One of required parameter is empty, shopDomain='%s' appKey='%s' appSecret='%s' shopToken='%s'", shopDomain, appKey, appSecret, shopToken))
}
Expand All @@ -62,17 +160,19 @@ func main() {
log.Fatalln(err)
}

downloadCmd.PersistentFlags().StringP("output", "o", fmt.Sprintf("%s", cwd), "output directory")
downloadCmd.PersistentFlags().StringP("dir", "d", fmt.Sprintf("%s", cwd), "directory where contents exists")
downloadCmd.PersistentFlags().String("domain", "", "ShopDomain of your shop ex:your-shop.myshopify.com")
downloadCmd.PersistentFlags().String("key", "", "Key of Admin API")
downloadCmd.PersistentFlags().String("secret", "", "Secret of Admin API")
downloadCmd.PersistentFlags().String("token", "", "AccessToken for Admin API generally same as secret if using Private App.")
downloadCmd.PersistentFlags().String("config", "", "configuration file which includes api key and so on")

deployCmd.PersistentFlags().StringP("input", "i", fmt.Sprintf("%s", cwd), "input directory")
deployCmd.PersistentFlags().StringP("dir", "d", fmt.Sprintf("%s", cwd), "directory where contents exists")
deployCmd.PersistentFlags().String("domain", "", "ShopDomain of your shop ex:your-shop.myshopify.com")
deployCmd.PersistentFlags().String("key", "", "Key of Admin API")
deployCmd.PersistentFlags().String("secret", "", "Secret of Admin API")
deployCmd.PersistentFlags().String("token", "", "AccessToken for Admin API generally same as secret if using Private App.")
deployCmd.PersistentFlags().String("config", "", "configuration file which includes api key and so on")

rootCmd.AddCommand(downloadCmd)
rootCmd.AddCommand(deployCmd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

手元でコマンドを実行すると、ショップの管理画面のコンテンツが更新されている様子です。

<img src="https://cdn.shopify.com/s/files/1/0512/0091/7703/files/2020-12-03_20.37.21_480x480.gif?v=1606995566" alt="デモ動画" />
![デモ動画](https://cdn.shopify.com/s/files/1/0512/0091/7703/files/2020-12-03_20.37.21_480x480.gif?v=1606995566)

## Shopifyでのコンテンツの編集について

Expand Down Expand Up @@ -84,7 +84,7 @@ Shopify関係ないですね。

バイナリを [Releaseページ](https://github.com/kogai/k9bookshelf/releases) に置いておくので、良かったら試してみて下さい。

------
---

次回は [ShoheiTai](https://qiita.com/ShoheiTai) さんの「Shopifyアプリの選定・運用ノウハウとか」です。
お楽しみに!
8 changes: 4 additions & 4 deletions contents/blogs/development/洋書店の始め方.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

取次のオンラインサービスにアカウントを作成する

https://getstarted.ingramcontent.com
[https://getstarted.ingramcontent.com](https://getstarted.ingramcontent.com)

ingramはアメリカの出版取次大手(トーハンみたいな感じ)

Expand All @@ -16,14 +16,14 @@ ipageにアカウントを作成する

動画

https://www.ingramcontent.com/retailers/ordering/ipage
[https://www.ingramcontent.com/retailers/ordering/ipage](https://www.ingramcontent.com/retailers/ordering/ipage)

FAQ

https://www.ingramcontent.com/publishers/lp/introducingipage-faq
[https://www.ingramcontent.com/publishers/lp/introducingipage-faq](https://www.ingramcontent.com/publishers/lp/introducingipage-faq)

書誌情報がダウンロードできる

種類が多い

BISAC https://www2.archivists.org/groups/standards-committee/book-industry-standards-and-communications-bisac
BISAC [https://www2.archivists.org/groups/standards-committee/book-industry-standards-and-communications-bisac](https://www2.archivists.org/groups/standards-committee/book-industry-standards-and-communications-bisac)
3 changes: 2 additions & 1 deletion contents/products/distributed-services-with-go.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- Goでマイクロサービスの1サービス(ログサービス)を作っていく
- 20年代のWeb開発入門として良いかも(UI層の話はないけど)
- もはや事業の最初期でも単一のサービスで構成されるアプリケーションはないと思う

- もはや事業の最初期でも単一のサービスで構成されるアプリケーションはないと思う
- 「分散システム」に期待して読み始めると、序盤は割合退屈かも
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ require (
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
golang.org/x/tools v0.0.0-20201121010211-780cb80bd7fb // indirect
gopkg.in/go-playground/assert.v1 v1.2.1
gopkg.in/yaml.v2 v2.4.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down

0 comments on commit 287e35e

Please sign in to comment.