Example #1
0
// MarshalJSON implements json.Marshaler interface
func (d PackageDiff) MarshalJSON() ([]byte, error) {
	serialized := struct {
		Left, Right *string
	}{}

	if d.Left != nil {
		serialized.Left = pointer.ToString(string(d.Left.Key("")))
	}
	if d.Right != nil {
		serialized.Right = pointer.ToString(string(d.Right.Key("")))
	}

	return json.Marshal(serialized)
}
Example #2
0
func aptlyRepoEdit(cmd *commander.Command, args []string) error {
	var err error
	if len(args) != 1 {
		cmd.Usage()
		return commander.ErrCommandError
	}

	repo, err := context.CollectionFactory().LocalRepoCollection().ByName(args[0])
	if err != nil {
		return fmt.Errorf("unable to edit: %s", err)
	}

	err = context.CollectionFactory().LocalRepoCollection().LoadComplete(repo)
	if err != nil {
		return fmt.Errorf("unable to edit: %s", err)
	}

	var uploadersFile *string

	context.Flags().Visit(func(flag *flag.Flag) {
		switch flag.Name {
		case "comment":
			repo.Comment = flag.Value.String()
		case "distribution":
			repo.DefaultDistribution = flag.Value.String()
		case "component":
			repo.DefaultComponent = flag.Value.String()
		case "uploaders-file":
			uploadersFile = pointer.ToString(flag.Value.String())
		}
	})

	if uploadersFile != nil {
		if *uploadersFile != "" {
			repo.Uploaders, err = deb.NewUploadersFromFile(*uploadersFile)
			if err != nil {
				return err
			}
		} else {
			repo.Uploaders = nil
		}
	}

	err = context.CollectionFactory().LocalRepoCollection().Update(repo)
	if err != nil {
		return fmt.Errorf("unable to edit: %s", err)
	}

	fmt.Printf("Local repo %s successfully updated.\n", repo)
	return err
}