cmd¶
Index¶
- Variables
- func Execute()
- func NewMdCmd(deps *MdDependencies) *cobra.Command
- func NewTaskAddCmd(deps *TaskAddDependencies) *cobra.Command
- func NewTaskCmd() *cobra.Command
- func ParseDateFromJournalFlag(journalFlag string, timeNow func() time.Time) (time.Time, error)
- func addBlockFlag(cmd *cobra.Command, flagVar *string, what string)
- func addJournalFlag(cmd *cobra.Command, flagVar *string)
- func addPageFlag(cmd *cobra.Command, flagVar *string, what string)
- func init()
- type MdDependencies
- type TaskAddDependencies
Variables¶
var backlogCmd = &cobra.Command{
Use: "backlog [partial page names]",
Short: "Aggregate tasks from multiple pages into a backlog",
Long: `The backlog command aggregates tasks from one or more pages into a unified backlog.
If partial page names are provided, only page titles that contain the provided names are processed.
Each line on the "backlog" page that includes references to other pages or tags generates a separate backlog.
The first page in the line determines the name of the backlog page.
Tasks are retrieved from all provided pages or tags.
This setup enables users to rearrange tasks using the arrow keys and manage task states (start/stop)
directly within the interface.`,
Run: func(_ *cobra.Command, args []string) {
path := os.Getenv("LOGSEQ_GRAPH_PATH")
api := internal.NewLogseqAPI(path,
os.Getenv("LOGSEQ_HOST_URL"), os.Getenv("LOGSEQ_API_TOKEN"))
graph := internal.OpenGraphFromPath(path)
reader := backlog.NewPageConfigReader(graph, "backlog")
proc := backlog.NewBacklog(graph, api, reader, time.Now)
err := proc.ProcessAll(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
contentCmd represents the content command.
var contentCmd = &cobra.Command{
Use: "content",
Short: "Append raw Markdown content to Logseq",
Long: `Append raw Markdown content to Logseq.
Pipe your content via stdin.
For now, it will be appended at the end of the current journal page.`,
Run: func(_ *cobra.Command, _ []string) {
graph := internal.OpenGraphFromPath(os.Getenv("LOGSEQ_GRAPH_PATH"))
stdin := internal.ReadFromStdin()
var targetDate time.Time
if journalFlag != "" {
parsedDate, err := time.Parse("2006-01-02", journalFlag)
if err != nil {
log.Fatalln("Invalid journal date format. Use YYYY-MM-DD:", err)
}
targetDate = parsedDate
} else {
targetDate = time.Now()
}
_, err := internal.AppendRawMarkdownToJournal(graph, targetDate, stdin)
if err != nil {
log.Fatalln(err)
}
},
}
mdCmd represents the md command using the default dependencies.
rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "lqd",
Short: "Logseq Doctor heals your Markdown files for Logseq",
Long: `Logseq Doctor heals your Markdown files for Logseq.
Convert flat Markdown to Logseq outline, clean up Markdown,
prevent invalid content, and more stuff to come.
"lqdpy" is the CLI tool originally written in Python; "lqd" is the Go version.
The intention is to slowly convert everything to Go.`,
}
taskCmd represents the task command using the default dependencies.
tidyUpCmd represents the tidyUp command.
var tidyUpCmd = &cobra.Command{
Use: "tidy-up file1.md [file2.md ...]",
Short: "Tidy up your Markdown files.",
Long: `Tidy up your Markdown files, checking for invalid content and fixing some of them automatically.
- Check for forbidden references to pages/tags
- Check for running tasks (DOING)
- Check for double spaces`,
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
graph := internal.OpenGraphFromPath(os.Getenv("LOGSEQ_GRAPH_PATH"))
exitCode := 0
for _, path := range args {
if internal.TidyUpOneFile(graph, path) != 0 {
exitCode = 1
}
}
os.Exit(exitCode)
},
}
func Execute¶
Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.
func NewMdCmd¶
NewMdCmd creates a new md command with the specified dependencies. If deps is nil, it uses default implementations.
func NewTaskAddCmd¶
NewTaskAddCmd creates a new task add subcommand with the specified dependencies. If deps is nil, it uses default implementations.
func NewTaskCmd¶
NewTaskCmd creates the parent task command.
func ParseDateFromJournalFlag¶
ParseDateFromJournalFlag parses the journal flag and returns the target date. If journalFlag is empty, it returns the current time from timeNow. If journalFlag is not empty, it parses it as YYYY-MM-DD format. Returns an error if the date format is invalid.
func addBlockFlag¶
addBlockFlag adds a --block/-b flag to the command with customizable help text.
func addJournalFlag¶
addJournalFlag adds a --journal/-j flag to the command.
func addPageFlag¶
addPageFlag adds a --page/-p flag to the command with customizable help text.
func init¶
type MdDependencies¶
MdDependencies holds all the dependencies for the md command.
type MdDependencies struct {
InsertFn func(*internal.InsertMarkdownOptions) error
OpenGraph func(string) *logseq.Graph
ReadStdin func() string
TimeNow func() time.Time
}
type TaskAddDependencies¶
TaskAddDependencies holds all the dependencies for the task add command.
type TaskAddDependencies struct {
AddTaskFn func(*internal.AddTaskOptions) error
OpenGraph func(string) *logseq.Graph
TimeNow func() time.Time
}
Generated by gomarkdoc