actions

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExportCmd = &cobra.Command{
	Use:    "export",
	Short:  "Exports data into given file.",
	PreRun: initDatabase,
	Run: func(cmd *cobra.Command, args []string) {
		exporter, err := exporters.GetExporter(common.ExporterType, common.ExportInto, "")
		if err != nil {
			log.Fatal(err)
		}

		exportingData := common.Database.FindAll()

		exporter.Export(exportingData)
	},
}
View Source
var GetCmd = &cobra.Command{
	Use:   "get",
	Short: "Fetches data from database.",
	PreRun: func(cmd *cobra.Command, args []string) {
		if _, err := os.Stat(common.Path); err == nil {
			initDatabase(cmd, args)
		} else {
			log.Fatal("Such database does not exist.")
		}
	},
	Run: func(cmd *cobra.Command, args []string) {
		result := make([]databases.Record, 0)

		if common.Service != "" {
			foundRecords := common.Database.FindByService(common.Service)
			if foundRecords != nil {
				result = append(result, foundRecords...)
			}
		} else {
			result = append(result, common.Database.FindAll()...)
		}

		toPrint, err := json.MarshalIndent(result, "", "    ")
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(string(toPrint))
	},
}
View Source
var ImportCmd = &cobra.Command{
	Use:    "import",
	Short:  "Imports data from given file.",
	PreRun: initDatabase,
	Run: func(cmd *cobra.Command, args []string) {
		importer, err := exporters.GetExporter(common.ImporterType, common.ImportFrom, common.Browser)
		if err != nil {
			log.Fatal(err)
		}

		importingData := importer.Import()

		for _, record := range importingData {
			common.Database.Insert(&record)
		}
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:    "remove",
	Short:  "Removes the data for some service.",
	PreRun: initDatabase,
	Run: func(cmd *cobra.Command, args []string) {
		id, err := cmd.Flags().GetInt64("id")
		if err != nil {
			log.Fatalf("Couldn't get id flag: %v", err)
		}

		record := common.Database.FindById(id)

		if record != nil {
			common.Database.Delete(*record)
		}
	},
}
View Source
var SaveCmd = &cobra.Command{
	Use:    "save",
	Short:  "Saves the data for some service.",
	PreRun: initDatabase,
	Run: func(cmd *cobra.Command, args []string) {
		record := databases.Record{
			Owner:   common.User,
			Service: common.Service,
			Data:    []byte(common.Data),
		}

		common.Database.Insert(&record)
	},
}
View Source
var UpdateCmd = &cobra.Command{
	Use:    "update",
	Short:  "Updates the data for some service.",
	PreRun: initDatabase,
	Run: func(cmd *cobra.Command, args []string) {
		record := common.Database.FindById(common.UpdateId)

		if record != nil {
			if common.Service != "" {
				record.Service = common.Service
			}

			if common.Data != "" {
				record.Data = []byte(common.Data)
			}

			common.Database.Update(*record)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL