Skip to content

Commit

Permalink
refactor: change flag for section directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tukaelu committed Aug 17, 2024
1 parent 84ff634 commit 5a3dc4a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions internal/cli/cmdEmpty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
}

Expand Down Expand Up @@ -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))
}

Expand Down
20 changes: 9 additions & 11 deletions internal/cli/cmdPull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}

Expand Down

0 comments on commit 5a3dc4a

Please sign in to comment.