From 5a3dc4a3cd737d596ccdf8072c8abd07e4fdc765 Mon Sep 17 00:00:00 2001 From: Tsukasa Nishiyama Date: Sat, 17 Aug 2024 09:57:44 +0900 Subject: [PATCH] refactor: change flag for section directory --- README.md | 6 +++--- internal/cli/cmdEmpty.go | 8 +++----- internal/cli/cmdPull.go | 20 +++++++++----------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f2344da..3c31a5a 100644 --- a/README.md +++ b/README.md @@ -93,10 +93,10 @@ Flags: -l, --locale=STRING Specify the locale to pull. If not specified, the default locale will be used. --raw It pulls raw data without converting it from HTML to Markdown. -a, --save-article It pulls and saves the article in addition to the translation. - --without-section-dir It doesn't save in a directory named after the section ID. + --with-section-dir A .md file will be created in the section ID directory. ``` -By default, the pull subcommand saves under `{contents_dir}/{section_id}`. You can also specify an option to output directly under `{contents_dir}/`. +By default, the pull subcommand saves under `{contents_dir}`. You can also specify an option to output directly under `{contents_dir}/{section_id}`. If a Translation or Article already exists at the specified local path, it will be overwritten. ### empty @@ -115,7 +115,7 @@ Flags: -p, --permission-group-id=INT Specify the permission group ID. If not specified, the default value will be used. -u, --user-segment-id=INT Specify the user segment ID. If not specified, the default value will be used. --save-article It saves the article in addition to the translation. - --without-section-dir It doesn't save in a directory named after the section ID. + --with-section-dir A .md file will be created in the section ID directory. ``` The empty subcommand should not be used when adding a new Translation to an existing Article. diff --git a/internal/cli/cmdEmpty.go b/internal/cli/cmdEmpty.go index b6bc33a..f2e2082 100644 --- a/internal/cli/cmdEmpty.go +++ b/internal/cli/cmdEmpty.go @@ -15,7 +15,7 @@ type CommandEmpty struct { PermissionGroupID int `name:"permission-group-id" short:"p" help:"Specify the permission group ID. If not specified, the default value will be used."` UserSegmentID *int `name:"user-segment-id" short:"u" help:"Specify the user segment ID. If not specified, the default value will be used."` SaveArticle bool `name:"save-article" help:"It saves the article in addition to the translation."` - WithoutSectionDir bool `name:"without-section-dir" help:"It doesn't save in a directory named after the section ID."` + WithSectionDir bool `name:"with-section-dir" short:"S" help:"A .md file will be created in the section ID directory."` client zendesk.Client `kong:"-"` } @@ -59,10 +59,8 @@ func (c *CommandEmpty) Run(g *Global) error { return err } - var saveDirPath string - if c.WithoutSectionDir { - saveDirPath = g.Config.ContentsDir - } else { + saveDirPath := g.Config.ContentsDir + if c.WithSectionDir { saveDirPath = filepath.Join(g.Config.ContentsDir, strconv.Itoa(a.SectionID)) } diff --git a/internal/cli/cmdPull.go b/internal/cli/cmdPull.go index da66d5a..3392648 100644 --- a/internal/cli/cmdPull.go +++ b/internal/cli/cmdPull.go @@ -10,13 +10,13 @@ import ( ) type CommandPull struct { - Locale string `name:"locale" short:"l" help:"Specify the locale to pull. If not specified, the default locale will be used."` - Raw bool `name:"raw" help:"It pulls raw data without converting it from HTML to Markdown."` - SaveArticle bool `name:"save-article" short:"a" help:"It pulls and saves the article in addition to the translation."` - WithoutSectionDir bool `name:"without-section-dir" help:"It doesn't save in a directory named after the section ID."` - ArticleIDs []int `arg:"" help:"Specify the article IDs to pull." type:"int"` - client zendesk.Client `kong:"-"` - converter converter.Converter `kong:"-"` + Locale string `name:"locale" short:"l" help:"Specify the locale to pull. If not specified, the default locale will be used."` + Raw bool `name:"raw" help:"It pulls raw data without converting it from HTML to Markdown."` + SaveArticle bool `name:"save-article" short:"a" help:"It pulls and saves the article in addition to the translation."` + WithSectionDir bool `name:"with-section-dir" short:"S" help:"A .md file will be created in the section ID directory."` + ArticleIDs []int `arg:"" help:"Specify the article IDs to pull." type:"int"` + client zendesk.Client `kong:"-"` + converter converter.Converter `kong:"-"` } func (c *CommandPull) AfterApply(g *Global) error { @@ -40,10 +40,8 @@ func (c *CommandPull) Run(g *Global) error { return err } - var saveDirPath string - if c.WithoutSectionDir { - saveDirPath = g.Config.ContentsDir - } else { + saveDirPath := g.Config.ContentsDir + if c.WithSectionDir { saveDirPath = filepath.Join(g.Config.ContentsDir, strconv.Itoa(a.SectionID)) }