File: options.go

package info (click to toggle)
golang-code.forgejo-f3-gof3 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,952 kB
  • sloc: sh: 100; makefile: 65
file content (60 lines) | stat: -rw-r--r-- 1,413 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT

package options

import (
	"context"
	"fmt"

	"code.forgejo.org/f3/gof3/v3/options"
	"code.forgejo.org/f3/gof3/v3/options/logger"

	"github.com/urfave/cli/v3"
)

type Options struct {
	options.Options
	logger.OptionsLogger

	Validation bool
	Directory  string
}

func (o *Options) GetURL() string    { return o.Directory }
func (o *Options) SetURL(url string) { o.Directory = url }

func (o *Options) FromFlags(ctx context.Context, c *cli.Command, prefix string) {
	o.Directory = c.String(forgeDirectoryOption(prefix))
	if o.Directory == "" {
		panic(fmt.Errorf("--%s is required", forgeDirectoryOption(prefix)))
	}
	o.Validation = c.Bool(forgeValidationOption(prefix))
}

func forgeValidationOption(direction string) string {
	return direction + "-validation"
}

func forgeDirectoryOption(direction string) string {
	return direction + "-directory"
}

func (o *Options) GetFlags(prefix, category string) []cli.Flag {
	flags := make([]cli.Flag, 0, 10)

	flags = append(flags, &cli.BoolFlag{
		Name:     forgeValidationOption(prefix),
		Usage:    "validate the JSON files against F3 JSON schemas",
		Category: prefix,
	})

	flags = append(flags, &cli.StringFlag{
		Name:     forgeDirectoryOption(prefix),
		Usage:    "path to the F3 archive",
		Category: prefix,
	})

	return flags
}