Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Command Line Interface https://github.com/siyuan-note/siyuan/issues/17674

Daniel3e0ad0610c03
diff --git a/kernel/cli/cmd/dailynote.go b/kernel/cli/cmd/dailynote.go
new file mode 100644
index 0000000000..eb604d8bfc
--- /dev/null
+++ b/kernel/cli/cmd/dailynote.go
@@ -0,0 +1,143 @@
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package cmd
+
+import (
+ "fmt"
+
+ "github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
+
+ "github.com/spf13/cobra"
+)
+
+var dailynoteCmd = &cobra.Command{
+ Use: "dailynote",
+ Short: "Daily note (dailynote) operations",
+}
+
+var dailynoteCreateCmd = &cobra.Command{
+ Use: "create --notebook <id>",
+ Short: "Create today's daily note",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ notebook, _ := cmd.Flags().GetString("notebook")
+ if notebook == "" {
+ return fmt.Errorf("--notebook is required")
+ }
+
+ p, _, err := model.CreateDailyNote(notebook)
+ if err != nil {
+ return err
+ }
+
+ model.FlushTxQueue()
+ model.AppendPushReloadFiletreeEntry()
+
+ id := util.GetTreeID(p)
+ fmt.Println(id)
+ return nil
+ },
+}
+
+var dailynoteAppendCmd = &cobra.Command{
+ Use: "append --notebook <id> [--data <markdown> | --file <path>]",
+ Short: "Append block to today's daily note",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ notebook, _ := cmd.Flags().GetString("notebook")
+ if notebook == "" {
+ return fmt.Errorf("--notebook is required")
+ }
+
+ data, err := resolveData(cmd)
+ if err != nil {
+ return err
+ }
+
+ p, _, err := model.CreateDailyNote(notebook)
+ if err != nil {
+ return err
+ }
+
+ parentID := util.GetTreeID(p)
+ dom := markdownToBlockDOM(data)
+ transactions := []*model.Transaction{{
+ DoOperations: []*model.Operation{{
+ Action: "appendInsert",
+ Data: dom,
+ ParentID: parentID,
+ }},
+ }}
+ model.PerformTransactions(&transactions)
+ model.FlushTxQueue()
+ model.AppendPushReloadProtyleEntry(parentID)
+ fmt.Println(parentID)
+ return nil
+ },
+}
+
+var dailynotePrependCmd = &cobra.Command{
+ Use: "prepend --notebook <id> [--data <markdown> | --file <path>]",
+ Short: "Prepend block to today's daily note",
+ RunE: func(cmd *cobra.Command, args []string) error {
+ notebook, _ := cmd.Flags().GetString("notebook")
+ if notebook == "" {
+ return fmt.Errorf("--notebook is required")
+ }
+
+ data, err := resolveData(cmd)
+ if err != nil {
+ return err
+ }
+
+ p, _, err := model.CreateDailyNote(notebook)
+ if err != nil {
+ return err
+ }
+
+ parentID := util.GetTreeID(p)
+ dom := markdownToBlockDOM(data)
+ transactions := []*model.Transaction{{
+ DoOperations: []*model.Operation{{
+ Action: "prependInsert",
+ Data: dom,
+ ParentID: parentID,
+ }},
+ }}
+ model.PerformTransactions(&transactions)
+ model.FlushTxQueue()
+ model.AppendPushReloadProtyleEntry(parentID)
+ fmt.Println(parentID)
+ return nil
+ },
+}
+
+func init() {
+ dailynoteCreateCmd.Flags().String("notebook", "", "notebook ID")
+
+ dailynoteAppendCmd.Flags().String("notebook", "", "notebook ID")
+ dailynoteAppendCmd.Flags().String("data", "", "markdown content")
+ dailynoteAppendCmd.Flags().String("file", "", "read content from file path (- for stdin)")
+
+ dailynotePrependCmd.Flags().String("notebook", "", "notebook ID")
+ dailynotePrependCmd.Flags().String("data", "", "markdown content")
+ dailynotePrependCmd.Flags().String("file", "", "read content from file path (- for stdin)")
+
+ rootCmd.AddCommand(dailynoteCmd)
+ dailynoteCmd.AddCommand(dailynoteCreateCmd)
+ dailynoteCmd.AddCommand(dailynoteAppendCmd)
+ dailynoteCmd.AddCommand(dailynotePrependCmd)
+}