Пример #1
0
func notebookShow(ctx *cli.Context) {

	conf, _ := config.New()
	c := api.NewClient(conf)

	if len(ctx.Args()) > 0 {
		for _, notebookId := range ctx.Args() {
			notes, err := c.Notes.NotesFromNotebook(notebookId)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to list Notes for Notebook %d: %s\n", notebookId, err)
			}
			fmt.Printf("#########\nNotebook %s\n#############\n", notebookId)
			for _, note := range notes {
				fmt.Printf("%+v\n", note)
			}
			fmt.Println("#########")
		}
	}

	if len(ctx.Args()) == 0 {
		notebooks, err := c.Notebooks.GetNotebooks()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to list Notebooks: %s\n", err)
		}
		for _, notebook := range notebooks {
			fmt.Printf("%+v\n", notebook)
		}
	}
}
Пример #2
0
func getSyncState(ctx *cli.Context) {
	conf, _ := config.New()
	c := api.NewClient(conf)
	state, err := c.User.GetSyncState()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get user sync state: %s\n", err)
	}
	fmt.Printf("%+v\n", state)
}
Пример #3
0
func info(ctx *cli.Context) {
	conf, _ := config.New()
	c := api.NewClient(conf)
	user, err := c.User.Info()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get user info: %s\n", err)
	}
	fmt.Printf("%+v\n", user)
	fmt.Printf("%+v\n", c.Account)
}
Пример #4
0
func register(ctx *cli.Context) {
	conf, _ := config.New()
	c := api.NewClient(conf)

	err := c.Auth.Register(conf)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to register user: %s\n", err)
	}
	//Display user info
	info(ctx)
}
Пример #5
0
func getImage(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		log.Fatal("Please provide just one argument as image id")
	} else {
		id := ctx.Args()[0]
		conf, _ := config.New()
		c := api.NewClient(conf)
		err := c.Files.GetAttach(id)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed get image: %s\n", err)
		}
	}
}
Пример #6
0
func updateUsername(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		log.Fatal("Please provide just one argument as filename")
	} else {
		name := ctx.Args()[0]
		conf, _ := config.New()
		c := api.NewClient(conf)
		err := c.User.UpdateUsername(name)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to update username: %s\n", err)
		}
	}
}
Пример #7
0
func updateLogo(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		log.Fatal("Please provide just one argument as new logo")
	} else {
		path := ctx.Args()[0]
		conf, _ := config.New()
		c := api.NewClient(conf)
		err := c.User.UpdateLogo(path)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to update logo: %s\n", err)
		}
	}
}
Пример #8
0
func updatePwd(ctx *cli.Context) {
	if len(ctx.Args()) != 2 {
		log.Fatal("Please provide old and new passwd")
	} else {
		old := ctx.Args()[0]
		pwd := ctx.Args()[1]
		conf, _ := config.New()
		c := api.NewClient(conf)
		err := c.User.UpdatePwd(old, pwd)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to update passwd: %s\n", err)
		}
	}
}
Пример #9
0
func noteState(ctx *cli.Context) {
	afterUsn := ctx.Int("after-usn")
	maxEntry := ctx.Int("max-entry")
	conf, _ := config.New()
	c := api.NewClient(conf)

	notes, err := c.Notes.GetSyncNotes(afterUsn, maxEntry)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get notes sync state: %s\n", err)
	}
	for _, note := range notes {
		fmt.Printf("%+v\n", note)
	}
}
Пример #10
0
func listTags(ctx *cli.Context) {

	afterUsn := ctx.Int("after-usn")
	maxEntry := ctx.Int("max-entry")

	conf, _ := config.New()
	c := api.NewClient(conf)
	tags, err := c.Tags.GetSyncTags(afterUsn, maxEntry)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to list tags: %s\n", err)
	}
	for _, tag := range tags {
		fmt.Printf("%+v\n", tag)
	}
}
Пример #11
0
func deleteTag(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		log.Fatal("Please provide just one argument as tag name to delete")
	} else {
		name := ctx.Args()[0]
		conf, _ := config.New()
		c := api.NewClient(conf)
		_, err := c.Tags.DeleteTag(name)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to delete tag: %s\n", err)
		} else {
			fmt.Printf("Tag %s deleted\n", name)
		}
	}
}
Пример #12
0
func addTag(ctx *cli.Context) {
	if len(ctx.Args()) != 1 {
		log.Fatal("Please provide just one argument as tag name to add")
	} else {
		name := ctx.Args()[0]
		conf, _ := config.New()
		c := api.NewClient(conf)
		tag, err := c.Tags.AddTag(name)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to add tag: %s\n", err)
		} else {
			fmt.Printf("%+v\n", tag)
		}
	}
}
Пример #13
0
func notebookCreate(ctx *cli.Context) {
	if len(ctx.Args()) == 0 {
		fmt.Fprintf(os.Stderr, "Failed to create notebook without a title\n")
	} else {
		title := ctx.Args()[0]
		pid := ctx.String("parent")
		seq := ctx.Int("seq")

		conf, _ := config.New()
		c := api.NewClient(conf)
		notebook, err := c.Notebooks.AddNotebook(title, pid, seq)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to create notebook: %s\n", err)
		}
		fmt.Printf("Notebook %s created\n%+v\n", title, notebook)
	}
}
Пример #14
0
func notebookUpdate(ctx *cli.Context) {
	if len(ctx.Args()) == 0 {
		fmt.Fprintf(os.Stderr, "Give the id of the notebook to update\n")
	} else {
		conf, _ := config.New()
		c := api.NewClient(conf)

		nid := ctx.Args()[0]
		title := ctx.String("title")
		pid := ctx.String("parent")
		seq := ctx.Int("seq")

		notebook, err := c.Notebooks.UpdateNotebook(nid, title, pid, seq)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to update notebook: %s\n", err)
		}
		fmt.Printf("Notebook %s updated\n%+v\n", notebook)
	}
}
Пример #15
0
func noteShow(ctx *cli.Context) {
	conf, _ := config.New()
	c := api.NewClient(conf)
	if len(ctx.Args()) > 0 {
		for _, noteId := range ctx.Args() {
			note, err := c.Notes.GetNoteAndContent(noteId)
			if err != nil {
				fmt.Fprintf(os.Stderr, "Failed to show notes %d: %s\n", noteId, err)
			}
			fmt.Printf("%+v\n", note)
		}
	}

	if len(ctx.Args()) == 0 {
		notes, err := c.Notes.GetNotes()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to list all Notes: %s\n", err)
		}
		for _, note := range notes {
			fmt.Printf("%+v\n", note)
		}
	}
}