cmd

package
v0.0.0-...-395a013 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NameArgEmpty = "name must have a non-whitespace value"
)

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Adds the provided series info to the list of series to keep track of",
	Example: heredoc.Doc(`To add a series with just a name and other information to be filled out:
	magnum add -n "Lady and the Tramp"
	Note: that the other fields will be filled in via prompts except the series status which is assumed to be ongoing

	To add a series with a special URL slug that does not follow the normal pattern for the publisher in question or is on its own page:
	magnum add -n "Re:ZERO -Starting Life in Another World" -s "re-starting-life-in-another-world"

	To add a series that is not ongoing (for example Completed):
	magnum add -n "Demon Slayer" -r "C"
	`),
	Run: func(cmd *cobra.Command, args []string) {
		err := ValidateAddSeriesFlags(seriesName)
		if err != nil {
			logger.WriteError(err.Error())
		}

		seriesInfo := config.GetConfig()
		if seriesInfo.HasSeries(seriesName) {
			logger.WriteInfo("The series already exists in the list.")

			return
		}

		var publisher = config.PublisherType(seriesPublisher)
		if strings.TrimSpace(seriesPublisher) == "" || !config.IsPublisherType(seriesPublisher) {
			publisher = selectPublisher()
		}

		var typeOfSeries = config.SeriesType(seriesType)
		if strings.TrimSpace(seriesType) == "" || !config.IsSeriesType(seriesType) {
			typeOfSeries = selectSeriesType()
		}

		var status = config.SeriesStatus(seriesStatus)
		if strings.TrimSpace(seriesStatus) == "" || !config.IsSeriesStatus(seriesStatus) {
			status = selectBookStatus()
		}

		var override *string
		if strings.TrimSpace(slugOverride) != "" {
			override = &slugOverride
		}

		newSeries := config.SeriesInfo{
			Name:         seriesName,
			Publisher:    publisher,
			Type:         typeOfSeries,
			SlugOverride: override,
			Status:       status,
		}

		warning := seriesInfo.AddSeries(newSeries, wikipediaTablesToParseOverride)
		if warning != "" {
			logger.WriteWarn(warning)
		}

		config.WriteConfig(seriesInfo)
	},
}

AddCmd represents the add book info command

View Source
var GetInfoCmd = &cobra.Command{
	Use:   "get-info",
	Short: "Gets the book release info for books that have been added to the list of series to track",
	Example: heredoc.Doc(`To get all of the release data for non-completed series:
	magnum get-info`),
	Run: func(cmd *cobra.Command, args []string) {
		seriesInfo := config.GetConfig()

		for i, series := range seriesInfo.Series {
			if series.Status != config.Completed || includeCompleted {
				seriesInfo.Series[i] = getSeriesVolumeInfo(series)
			}
		}

		config.WriteConfig(seriesInfo)
	},
}

GetInfoCmd represents the get book info command

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "Lists the names of each of the series that is currently being tracked",
	Example: heredoc.Doc(`To show a list of all series names that are being tracked:
	magnum list

	To include information like publisher, status, series, etc.:
	magnum list -v
	`),
	Run: func(cmd *cobra.Command, args []string) {
		seriesInfo := config.GetConfig()

		if len(seriesInfo.Series) == 0 {
			logger.WriteInfo("No series have been added to the list to keep track of.")

			return
		}

		var (
			filterOnPublisher    = strings.TrimSpace(seriesPublisher) != "" && config.IsPublisherType(seriesPublisher)
			publisherType        = config.PublisherType(seriesPublisher)
			filterOnSeriesType   = strings.TrimSpace(seriesType) != "" && config.IsSeriesType(seriesType)
			typeOfSeries         = config.SeriesType(seriesType)
			filterOnSeriesStatus = strings.TrimSpace(seriesStatus) != "" && config.IsSeriesStatus(seriesStatus)
			statusOfSeries       = config.SeriesStatus(seriesStatus)
		)
		for _, series := range seriesInfo.Series {
			if (filterOnPublisher && publisherType != series.Publisher) || (filterOnSeriesType && typeOfSeries != series.Type) || (filterOnSeriesStatus && statusOfSeries != series.Status) {
				continue
			}

			logger.WriteInfo(series.Name)
			if verbose {
				logger.WriteInfo("Status: " + config.SeriesStatusToDisplayText(series.Status))
				logger.WriteInfo("Publisher: " + string(series.Publisher))
				logger.WriteInfo("Type: " + config.SeriesTypeToDisplayText(series.Type))
				logger.WriteInfo(fmt.Sprintf("Total Volumes: %d", series.TotalVolumes))

				var slugOverride = "N/A"
				if series.SlugOverride != nil {
					slugOverride = *series.SlugOverride
				}
				logger.WriteInfo("Slug Override: " + slugOverride)

				logger.WriteInfo("")
			}
		}
	},
}

ListCmd represents the add book info command

View Source
var RemoveCmd = &cobra.Command{
	Use:   "remove",
	Short: "Removes the provided series from the list of series to keep track of",
	Example: heredoc.Doc(`To remove a series use the following command:
	magnum remove -n "Lady and the Tramp"
	`),
	Run: func(cmd *cobra.Command, args []string) {
		err := ValidateRemoveSeriesFlags(seriesName)
		if err != nil {
			logger.WriteError(err.Error())
		}

		seriesInfo := config.GetConfig()
		if !seriesInfo.RemoveSeriesIfExists(seriesName) {
			logger.WriteInfo("The series does not exists in the list.")

			return
		}

		config.WriteConfig(seriesInfo)

		logger.WriteInfo(fmt.Sprintf("The %q was removed from the series list.", seriesName))
	},
}

RemoveCmd represents the remove book info command

View Source
var SetStatus = &cobra.Command{
	Use:   "set-status",
	Short: "Sets the status of the provided/selected book name",
	Example: heredoc.Doc(`To set the status of a book you know the name of:
	magnum set-status -n "book_name"
	This will result in being prompted for a status for that book.

	To set the status of a book you know the name and status of:
	magnum set-status -n "book_name" -s C

	To set the status of a book by using the cli selection options:
	magnum set-status

	To set the status of a book and include the completed series:
	magnum set-status -c
	`),
	Run: func(cmd *cobra.Command, args []string) {
		seriesInfo := config.GetConfig()

		if len(seriesInfo.Series) == 0 {
			logger.WriteInfo("No series have been added to the list to keep track of.")

			return
		}

		var name = bookName
		if strings.TrimSpace(name) == "" {
			name = selectBookName(seriesInfo.Series, false)

			logger.WriteInfo(fmt.Sprintf("%q selected", name))
		}

		var status = config.SeriesStatus(bookStatus)
		if !config.IsSeriesStatus(bookStatus) {
			logger.WriteWarn(fmt.Sprintf(`Status %q is not a valid book status, so it is being ignored`, bookStatus))

			bookStatus = ""
		}

		logger.WriteInfo(bookStatus)
		if strings.TrimSpace(bookStatus) == "" {
			status = selectBookStatus()

			logger.WriteInfo(fmt.Sprintf("%q selected", status))
		}

		var foundSeriesToUpdate = false
		for i, series := range seriesInfo.Series {
			if name == series.Name {
				foundSeriesToUpdate = true
				seriesInfo.Series[i].Status = status
				break
			}
		}

		if !foundSeriesToUpdate {
			logger.WriteError(fmt.Sprintf("\n"+`Failed to find %q to set the status to %s.`, seriesName, status))
		}

		config.WriteConfig(seriesInfo)

		logger.WriteInfo(fmt.Sprintf("\n"+`Successfully set %q to have a status of %s.`, name, status))
	},
}

SetStatus represents the set book status command

View Source
var ShowInfoCmd = &cobra.Command{
	Use:   "show-info",
	Short: "Shows each series that has upcoming releases along with when the releases are in the order they are going to be released",
	Example: heredoc.Doc(`To show upcoming releases in order of when they are releasing:
	magnum show-info
	`),
	Run: func(cmd *cobra.Command, args []string) {
		seriesInfo := config.GetConfig()

		if len(seriesInfo.Series) == 0 {
			logger.WriteInfo("No series have been added to the list to keep track of.")

			return
		}

		var unreleasedVolumes []config.ReleaseInfo
		for _, series := range seriesInfo.Series {
			if len(series.UnreleasedVolumes) == 0 {
				continue
			}

			for i, unreleasedVolume := range series.UnreleasedVolumes {
				if unreleasedVolume.ReleaseDate == defaultReleaseDate {
					continue
				}

				if strings.HasPrefix(unreleasedVolume.Name, "Vol") {
					series.UnreleasedVolumes[i].Name = series.Name + ": " + unreleasedVolume.Name
				}

				unreleasedVolumes = append(unreleasedVolumes, series.UnreleasedVolumes[i])
			}
		}

		if len(unreleasedVolumes) == 0 {
			logger.WriteInfo("No release are upcoming")
			return
		}

		logger.WriteInfo("Upcoming releases:")
		logger.WriteInfo("")
		sort.Slice(unreleasedVolumes, func(i, j int) bool {
			if unreleasedVolumes[i].ReleaseDate == defaultReleaseDate {
				return false
			} else if unreleasedVolumes[j].ReleaseDate == defaultReleaseDate {
				return true
			}

			date1 := parseVolumeReleaseDate(unreleasedVolumes[i].Name, unreleasedVolumes[i].ReleaseDate)

			date2 := parseVolumeReleaseDate(unreleasedVolumes[j].Name, unreleasedVolumes[j].ReleaseDate)

			return date1.Before(date2)
		})

		var today = time.Now()
		var oneWeekAgo = today.AddDate(0, 0, -7)
		var nextMonth = today.AddDate(0, 1, 0)
		for _, unreleasedVolume := range unreleasedVolumes {
			var displayText = getUnreleasedVolumeDisplayText(unreleasedVolume.Name, unreleasedVolume.ReleaseDate)
			if unreleasedVolume.ReleaseDate == defaultReleaseDate {
				logger.WriteInfo(displayText)
				continue
			}

			date := parseVolumeReleaseDate(unreleasedVolume.Name, unreleasedVolume.ReleaseDate)
			if date.Before(oneWeekAgo) {
				logger.WriteInfoWithColor(displayText, color.FgRed)
			} else if date.Before(nextMonth) {
				logger.WriteInfoWithColor(displayText, color.FgYellow)
			} else {
				logger.WriteInfo(displayText)
			}
		}
	},
}

ShowInfoCmd represents the add book info command

Functions

func Execute

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 ValidateAddSeriesFlags

func ValidateAddSeriesFlags(seriesName string) error

func ValidateRemoveSeriesFlags

func ValidateRemoveSeriesFlags(seriesName string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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