Skip to content

Commit

Permalink
feat: refactoring commands
Browse files Browse the repository at this point in the history
  • Loading branch information
WolverMinion committed Sep 24, 2023
1 parent 0a53f11 commit a25ccdc
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 161 deletions.
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"version": "0.2.0",
"configurations": [
{
"name": "github-config export orga",
"name": "github-config organization export",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": [
"organization",
"export",
"-t",
"${env:GITHUB_OAUTH}",
Expand All @@ -28,12 +29,13 @@
}
},
{
"name": "github-config export repo",
"name": "github-config repository export",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "main.go",
"args": [
"repository",
"export",
"-t",
"${env:GITHUB_OAUTH}",
Expand Down
17 changes: 12 additions & 5 deletions cmd/constance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ const (
flag_dry_run_description = "[default none] / Must be \"none\" or \"server\". If server strategy, only print the config informations that would be sent"

// commands
cmd_export = "export"
cmd_diff = "diff"
cmd_sync = "sync"
cmd_organization = "organization"
cmd_repository = "repository"
cmd_export = "export"
cmd_diff = "diff"
cmd_sync = "sync"

cmd_organization = "organization"
cmd_organization_desc_short = "organization command with subcommands"
cmd_organization_desc_long = `github organization command with subcommands.`

cmd_repository = "repository"
cmd_repository_desc_short = "repository command with subcommands"
cmd_repository_desc_long = `github repository command with subcommands.
`
)
43 changes: 0 additions & 43 deletions cmd/diff.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/diff_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var diffOrganizationCmd = &cobra.Command{
Use: cmd_organization,
Use: cmd_diff,
Short: "export the github organization config",
Long: `export the github organization configuration in the backup repository.
Expand Down Expand Up @@ -71,7 +71,7 @@ var diffOrganizationCmd = &cobra.Command{
}

func init() {
diffCmd.AddCommand(diffOrganizationCmd)
organizationCmd.AddCommand(diffOrganizationCmd)

diffOrganizationCmd.Flags().StringVarP(&gh_personal_token, flag_gh_token, flag_gh_token_short, "", flag_gh_token_description)
diffOrganizationCmd.Flags().StringVarP(&gh_organization, flag_gh_orga, flag_gh_orga_short, "", flag_gh_orga_description)
Expand Down
43 changes: 0 additions & 43 deletions cmd/export.go

This file was deleted.

26 changes: 19 additions & 7 deletions cmd/export_organization.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand All @@ -10,11 +25,9 @@ import (
)

var exportOrganizationCmd = &cobra.Command{
Use: cmd_organization,
Short: "export the github organization config",
Long: `export the github organization configuration in the backup repository.
......`,
Use: cmd_export,
Short: "export organization ",
Long: `export organization data`,
Run: func(cmd *cobra.Command, args []string) {
slog.Debug("command started", "cmd", cmd.CommandPath())

Expand Down Expand Up @@ -102,12 +115,11 @@ var exportOrganizationCmd = &cobra.Command{
}

slog.Debug("command ended", "cmd", cmd.CommandPath())

},
}

func init() {
exportCmd.AddCommand(exportOrganizationCmd)
organizationCmd.AddCommand(exportOrganizationCmd)

exportOrganizationCmd.Flags().StringVarP(&gh_personal_token, flag_gh_token, flag_gh_token_short, "", flag_gh_token_description)
exportOrganizationCmd.Flags().StringVarP(&gh_organization, flag_gh_orga, flag_gh_orga_short, "", flag_gh_orga_description)
Expand Down
42 changes: 28 additions & 14 deletions cmd/export_repository.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand All @@ -9,12 +24,11 @@ import (
"github.com/spf13/cobra"
)

var repositoryCmd = &cobra.Command{
Use: cmd_repository,
Short: "export the github repository config",
Long: `export the github repository configuration in the backup repository.
......`,
// exportRepositoryCmd represents the export command
var exportRepositoryCmd = &cobra.Command{
Use: cmd_export,
Short: "export repository ",
Long: `export repository data`,
Run: func(cmd *cobra.Command, args []string) {
slog.Debug("command started", "cmd", cmd.CommandPath())

Expand Down Expand Up @@ -67,18 +81,18 @@ var repositoryCmd = &cobra.Command{
}

slog.Debug("command ended", "cmd", cmd.CommandPath())

},
}

func init() {
exportCmd.AddCommand(repositoryCmd)
repositoryCmd.AddCommand(exportRepositoryCmd)

exportRepositoryCmd.Flags().StringVarP(&gh_personal_token, flag_gh_token, flag_gh_token_short, "", flag_gh_token_description)
exportRepositoryCmd.Flags().StringVarP(&gh_organization, flag_gh_orga, flag_gh_orga_short, "", flag_gh_orga_description)
exportRepositoryCmd.Flags().StringVarP(&gh_repository, flag_gh_repo, flag_gh_repo_short, "", flag_gh_repo_description)

repositoryCmd.Flags().StringVarP(&gh_personal_token, flag_gh_token, flag_gh_token_short, "", flag_gh_token_description)
repositoryCmd.Flags().StringVarP(&gh_organization, flag_gh_orga, flag_gh_orga_short, "", flag_gh_orga_description)
repositoryCmd.Flags().StringVarP(&gh_repository, flag_gh_repo, flag_gh_repo_short, "", flag_gh_repo_description)
exportRepositoryCmd.MarkFlagRequired(flag_gh_token)
exportRepositoryCmd.MarkFlagRequired(flag_gh_orga)
exportRepositoryCmd.MarkFlagRequired(flag_gh_repo)

repositoryCmd.MarkFlagRequired(flag_gh_token)
repositoryCmd.MarkFlagRequired(flag_gh_orga)
repositoryCmd.MarkFlagRequired(flag_gh_repo)
}
23 changes: 23 additions & 0 deletions cmd/organization.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"golang.org/x/exp/slog"

"github.com/spf13/cobra"
)

var organizationCmd = &cobra.Command{
Use: cmd_organization,
Short: cmd_organization_desc_short,
Long: cmd_organization_desc_long,
Run: func(cmd *cobra.Command, args []string) {
slog.Debug("command started", "cmd", cmd.CommandPath())
cmd.Usage()
slog.Debug("command ended", "cmd", cmd.CommandPath())

},
}

func init() {
rootCmd.AddCommand(organizationCmd)
}
22 changes: 22 additions & 0 deletions cmd/repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"golang.org/x/exp/slog"

"github.com/spf13/cobra"
)

var repositoryCmd = &cobra.Command{
Use: cmd_repository,
Short: cmd_repository_desc_short,
Long: cmd_repository_desc_long,
Run: func(cmd *cobra.Command, args []string) {
slog.Debug("command started", "cmd", cmd.CommandPath())
cmd.Usage()
slog.Debug("command ended", "cmd", cmd.CommandPath())
},
}

func init() {
rootCmd.AddCommand(repositoryCmd)
}
43 changes: 0 additions & 43 deletions cmd/sync.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/sync_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

var syncOrganizationCmd = &cobra.Command{
Use: cmd_organization,
Use: cmd_sync,
Short: "export the github organization config",
Long: `export the github organization configuration in the backup repository.
Expand Down Expand Up @@ -68,7 +68,7 @@ var syncOrganizationCmd = &cobra.Command{
}

func init() {
syncCmd.AddCommand(syncOrganizationCmd)
organizationCmd.AddCommand(syncOrganizationCmd)

syncOrganizationCmd.Flags().StringVarP(&gh_personal_token, flag_gh_token, flag_gh_token_short, "", flag_gh_token_description)
syncOrganizationCmd.Flags().StringVarP(&gh_organization, flag_gh_orga, flag_gh_orga_short, "", flag_gh_orga_description)
Expand Down

0 comments on commit a25ccdc

Please sign in to comment.