Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to dry-run operations #148

Merged
merged 3 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Configuration arguments are as follows:
| Name | Value Type | Example Value | Required | Default |
| --- | --- | --- | --- | --- |
| log-level | string | "warn" | false | "info" |
| confirm | bool | false | false | false |
| github-token | string | | true | null |
| jira-user | string | "[email protected]" | false | null |
| jira-pass | string | | false | null |
Expand All @@ -75,6 +76,10 @@ Configuration arguments are as follows:
`log-level` is the minimum level which will be logged; any output below
this value will be discarded.

`confirm` is for confirming a production run, it must be explicitly set
to `true`, otherwise it will be a dry run by default and no changes
will be executed in Jira

`github-token` is a personal access token used to access GitHub as a
specific user.

Expand Down
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ func init() {
)

RootCmd.PersistentFlags().BoolVarP(
&opts.DryRun,
options.ConfigKeyDryRun,
"d",
options.DefaultDryRun,
"print out actions to be taken, but do not execute them",
&opts.Confirm,
options.ConfigKeyConfirm,
"c",
options.DefaultConfirm,
"if set to true, all actions will be executed, otherwise they are just printed out (dry run)",
)

RootCmd.PersistentFlags().DurationVarP(
Expand Down
30 changes: 16 additions & 14 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ func (c *Config) GetSinceParam() time.Time {
return c.since
}

// IsDryRun returns whether the application is running in dry-run mode or not.
// IsDryRun returns whether the application is running in confirmed mode or not.
func (c *Config) IsDryRun() bool {
return c.cmdConfig.GetBool(options.ConfigKeyDryRun)
return !c.cmdConfig.GetBool(options.ConfigKeyConfirm)
}

// IsDaemon returns whether the application is running as a daemon.
Expand Down Expand Up @@ -272,18 +272,20 @@ func (c *Config) SetJiraToken(token *oauth1.Token) {

// configFile is a serializable representation of the current Viper configuration.
type configFile struct {
LogLevel string `json:"log-level" mapstructure:"log-level"`
GithubToken string `json:"github-token" mapstructure:"github-token"`
JiraUser string `json:"jira-user" mapstructure:"jira-user"`
JiraToken string `json:"jira-token" mapstructure:"jira-token"`
JiraSecret string `json:"jira-secret" mapstructure:"jira-secret"`
JiraKey string `json:"jira-private-key-path" mapstructure:"jira-private-key-path"`
JiraCKey string `json:"jira-consumer-key" mapstructure:"jira-consumer-key"`
RepoName string `json:"repo-name" mapstructure:"repo-name"`
JiraURI string `json:"jira-uri" mapstructure:"jira-uri"`
JiraProject string `json:"jira-project" mapstructure:"jira-project"`
Since string `json:"since" mapstructure:"since"`
Timeout time.Duration `json:"timeout" mapstructure:"timeout"`
LogLevel string `json:"log-level,omitempty" mapstructure:"log-level"`
GithubToken string `json:"github-token,omitempty" mapstructure:"github-token"`
JiraUser string `json:"jira-user,omitempty" mapstructure:"jira-user"`
JiraPass string `json:"jira-pass,omitempty" mapstructure:"jira-pass"`
justaugustus marked this conversation as resolved.
Show resolved Hide resolved
JiraToken string `json:"jira-token,omitempty" mapstructure:"jira-token"`
JiraSecret string `json:"jira-secret,omitempty" mapstructure:"jira-secret"`
JiraKey string `json:"jira-private-key-path,omitempty" mapstructure:"jira-private-key-path"`
JiraCKey string `json:"jira-consumer-key,omitempty" mapstructure:"jira-consumer-key"`
RepoName string `json:"repo-name,omitempty" mapstructure:"repo-name"`
JiraURI string `json:"jira-uri,omitempty" mapstructure:"jira-uri"`
JiraProject string `json:"jira-project,omitempty" mapstructure:"jira-project"`
Since string `json:"since,omitempty" mapstructure:"since"`
Confirm bool `json:"confirm,omitempty" mapstructure:"confirm"`
Timeout time.Duration `json:"timeout,omitempty" mapstructure:"timeout"`
}

// SaveConfig updates the `since` parameter to now, then saves the configuration file.
Expand Down
6 changes: 3 additions & 3 deletions internal/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Options struct {
JiraProject string
// TODO(options): Should this be a time type?
Since string
DryRun bool
Confirm bool
Timeout time.Duration
Period time.Duration
}
Expand All @@ -48,7 +48,7 @@ const (
ConfigKeyLogLevel = "log-level"
ConfigKeyConfigFile = "config"
ConfigKeySince = "since"
ConfigKeyDryRun = "dry-run"
ConfigKeyConfirm = "confirm"
ConfigKeyPeriod = "period"
ConfigKeyTimeout = "timeout"

Expand All @@ -73,7 +73,7 @@ const (
DefaultLogLevel = logrus.InfoLevel
DefaultConfigFileName = ".issue-sync.json"
DefaultSince = "1970-01-01T00:00:00+0000"
DefaultDryRun = false
DefaultConfirm = false
DefaultPeriod = time.Hour
DefaultTimeout = 30 * time.Second
)
Expand Down