package growsync import ( "context" "flag" "io" "golang.org/x/xerrors" ) type pushCmd struct{} func (pc *pushCmd) name() string { return "push" } func (pc *pushCmd) description() string { return "push from growi web app" } func (pc *pushCmd) run(ctx context.Context, argv []string, config *growiConfig, stdWriter io.Writer, errorWriter io.Writer) error { fs := flag.NewFlagSet("growsync push", flag.ContinueOnError) fs.SetOutput(errorWriter) if err := fs.Parse(argv); err != nil { return xerrors.Errorf("[error] failed parse argv %+w", err) } if fs.NArg() < 1 { return xerrors.New("usage: growsync push [md file]") } client, err := NewGrowiClient(config.URL, config.TOKEN) if err != nil { return xerrors.Errorf("[error] failed growi client %+w", err) } markdownPATH := fs.Arg(0) growiSystemPath := convertGrowiSystemPath(markdownPATH) id, err := client.IsExistsPageOnGrowi(growiSystemPath) if err != nil { return xerrors.Errorf("[error] failed get page %s %+w", growiSystemPath, err) } if id == nil { return client.CreateNewPage(growiSystemPath, markdownPATH) } return client.UpdatePage(growiSystemPath, markdownPATH) }