Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# For next release
* **Raphael Pour**
* cmd: add slug completion

*Not released yet*

# Minor Release v2.2.0 (2025-02-18)
* **Raphael Pour**
* metadata: render posts with date instead of full timestamp
Expand Down
53 changes: 53 additions & 0 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cmd

import (
"os"
"strings"

"github.com/spf13/cobra"
)

var CompletionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: "To load completions",
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
_ = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
_ = cmd.Root().GenZshCompletion(os.Stdout)
case "fish":
_ = cmd.Root().GenFishCompletion(os.Stdout, true)
case "powershell":
_ = cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}

func init() {
rootCmd.AddCommand(CompletionCmd)
}

func SlugCompletion(
_ *cobra.Command,
_ []string,
toComplete string,
) ([]cobra.Completion, cobra.ShellCompDirective) {
files, err := os.ReadDir(BlogPath)
if err != nil {
return []cobra.Completion{}, cobra.ShellCompDirectiveNoFileComp
}

candidates := make([]cobra.Completion, 0)
for _, file := range files {
if strings.HasPrefix(file.Name(), toComplete) {
candidates = append(candidates, file.Name())
}
}

return candidates, cobra.ShellCompDirectiveNoFileComp
}
1 change: 1 addition & 0 deletions cmd/draft.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ var draftCmd = &cobra.Command{
func init() {
postCmd.AddCommand(draftCmd)
draftCmd.Flags().StringVarP(&Slug, "slug", "s", "", "Slug of the post (required)")
_ = draftCmd.RegisterFlagCompletionFunc("slug", SlugCompletion)
}
1 change: 1 addition & 0 deletions cmd/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ var publishCmd = &cobra.Command{
func init() {
postCmd.AddCommand(publishCmd)
publishCmd.Flags().StringVarP(&Slug, "slug", "s", "", "Slug of the post (required)")
_ = publishCmd.RegisterFlagCompletionFunc("slug", SlugCompletion)
}
1 change: 1 addition & 0 deletions cmd/rewriteConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var rewriteMetadataCmd = &cobra.Command{
func init() {
adminCmd.AddCommand(rewriteMetadataCmd)
rewriteMetadataCmd.Flags().StringVarP(&Slug, "slug", "s", "", "Slug of the post. Use all if empty.")
_ = rewriteMetadataCmd.RegisterFlagCompletionFunc("slug", SlugCompletion)
}

func rewriteMetadata(postPath string) error {
Expand Down
2 changes: 2 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ func init() {
updateCmd.Flags().StringVarP(&Slug, "slug", "s", "", "Slug of the post (required)")
updateCmd.Flags().BoolVarP(&AppendStdin, "append", "a", false, "Append stdin to post")
updateCmd.Flags().BoolVarP(&Interactive, "interactive", "i", false, "Opend default editor with existing post")

_ = updateCmd.RegisterFlagCompletionFunc("slug", SlugCompletion)
}
55 changes: 44 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
module github.com/RaphaelPour/blogctl

go 1.23.0
go 1.24.0

require (
github.com/alecthomas/chroma v0.10.0
github.com/fatih/color v1.16.0
github.com/gomarkdown/markdown v0.0.0-20231222211730-1d6d20845b47
github.com/gorilla/feeds v1.1.2
github.com/fatih/color v1.18.0
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a
github.com/gorilla/feeds v1.2.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.8.0
github.com/spf13/cobra v1.10.1
github.com/stretchr/testify v1.8.4
)

require (
github.com/MarkusFreitag/changelogger v0.7.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/clipperhouse/uax29/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/google/go-github/v30 v30.1.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.16.0 // indirect
github.com/rhysd/go-github-selfupdate v1.2.3 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra-cli v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/spf13/viper v1.10.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
github.com/ulikunitz/xz v0.5.15 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/oauth2 v0.32.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.30.0 // indirect
gopkg.in/AlecAivazis/survey.v1 v1.8.8 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

tool (
github.com/MarkusFreitag/changelogger
github.com/spf13/cobra-cli
)
Loading
Loading