add create functionnality

This commit is contained in:
bcharest 2023-07-01 00:49:45 -04:00
parent 03ddddd2e2
commit 71fe930228
9 changed files with 318 additions and 85 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
release/

View File

@ -2,20 +2,26 @@
version: '3'
# Variables
#### Variables ####
# # # # # # # # # #
vars:
## Commands Go ##
#### Commands Go ####
GOCMD: go
GOBUILD: "{{.GOCMD}} build -o"
GORUN: "{{.GOCMD}} run"
GOTEST: "{{.GOCMD}} test -v"
GOCOVER: "{{.GOCMD}} test -v --cover"
# Variables to get version
#### Variables to get version ####
VERSION:
sh: cd version/ && versionManager go version
## Binary name of kode-creator ##
#### Variable HOME of user ####
HOME:
sh: echo $HOME
#### Binary name of kode-creator ####
WINDOWS_BINARY_NAME: ./release/windows/{{.VERSION}}/kode-creator.exe
LINUX_BINARY_NAME: ./release/linux/{{.VERSION}}/kode-creator
@ -27,27 +33,76 @@ vars:
# GOARCH: amd64
tasks:
###### LINUX ######
######### L I N U X S E C T I O N ##########
# # # # # # # # # # # # # # # # # # # # # # # # #
#### Version Manager ####
## Make sure you have PATH the versionManager !!!
linux-version:
1.0-linux-version-build:
cmds:
- "cd ./version/ && versionManager go build"
# silent: true
1.1-linux-version-patch:
cmds:
- "cd ./version/ && versionManager go patch"
1.2-linux-version-minor:
cmds:
- "cd ./version/ && versionManager go minor"
1.3-linux-version-major:
cmds:
- "cd ./version/ && versionManager go major"
## Build ##
linux-build:
#### Build ####
2.0-linux-build:
cmds:
- "{{.GOBUILD}} {{.LINUX_BINARY_NAME}} -v"
# silent: true
## change Build version and build
linux-vbuild:
#### change Build, patch, minor or major version and BUILD ####
3.0-linux-vbuild:
cmds:
- task: linux-version
- task: linux-build
- task: 1.0-linux-version-build
- task: 2.0-linux-build
3.1-linux-vpatch:
cmds:
- task: 1.1-linux-version-patch
- task: 2.0-linux-build
3.2-linux-vminor:
cmds:
- task: 1.2-linux-version-minor
- task: 2.0-linux-build
3.3-linux-vmajor:
cmds:
- task: 1.3-linux-version-major
- task: 2.0-linux-build
#### install on LINUX OS ####
4.0-linux-install:
cmds:
- "cp {{.LINUX_BINARY_NAME}} {{.HOME}}/dev/outils/kode-creator/"
- "chmod +x {{.HOME}}/dev/outils/kode-creator/kode-creator"
- "cp ./config.yml {{.HOME}}/dev/outils/kode-creator/"
#### LINUX - Build ==> Install ####
5.0-LINUX-bi:
cmds:
- task: 3.0-linux-vbuild
- task: 4.0-linux-install
5.1-LINUX-pi:
cmds:
- task: 3.1-linux-vpatch
- task: 4.0-linux-install
5.2-LINUX-mini:
cmds:
- task: 3.2-linux-vminor
- task: 4.0-linux-install
5.3-LINUX-maji:
cmds:
- task: 3.3-linux-vmajor
- task: 4.0-linux-install
###### WINDOWS ######
######### W I N D O W S S E C T I O N ##########
# # # # # # # # # # # # # # # # # # # # # # # # # # #
## Make sure you have PATH the versionManager.exe !!!
windows-version:
cmds:
@ -67,3 +122,5 @@ tasks:

View File

@ -39,6 +39,8 @@ var CreateCmd = &cobra.Command{
},
}
// The CreateProject function creates a project structure, including a directory, version control, and
// a readme file, based on the provided arguments and flags.
func CreateProject(cmd *cobra.Command, args []string) error {
godotenv.Load()
@ -65,11 +67,70 @@ func CreateProject(cmd *cobra.Command, args []string) error {
fmt.Println("Structure Name:" + data.Name)
// Make API request to create Github project
jsonData, _ := json.Marshal(data)
// if directory flag is set, create structure in current directory
if CfgGlobal.GetCreateDirectoryFlag() {
// Create directory of the project
CreateProjectStructure(data)
// if version flag is set, create version control in project
if CfgGlobal.GetCreateVersionFlag() {
fmt.Println("==> Creating version control...")
}
// if readme flag is set, create readme in project
if CfgGlobal.GetCreateReadmeFlag() {
fmt.Println("==> Creating readme...")
isCreated := CreateReadme(name, description, "BC", "")
if isCreated {
fmt.Println("==> Created README.md")
}
}
}
// if github flag is set, create structure in github
if CfgGlobal.GetCreateGitFlag() {
} else if CfgGlobal.GetCreateTeaFlag() {
err := CreateGiteaProject(data, cmd, args)
if err != nil {
log.Fatal(err)
}
}
return nil
}
// The function creates a directory for a project and changes the current working directory to the
// newly created directory.
func CreateProjectStructure(project structures.Project) {
fmt.Println("==> Creating directory...")
// Create directory of the project
fmt.Println("==> Creating directory...")
utils.CreateDir(project.Name)
fmt.Println("==> Created directory")
// Change to project directory
err := os.Chdir(project.Name)
if err != nil {
log.Fatal(err)
}
}
// The function `CreateGiteaProject` creates a new Gitea project, initializes a Git repository, and
// makes an initial commit.
func CreateGiteaProject(prj structures.Project, cmd *cobra.Command, args []string) error {
// Make API request to create Gitea project
jsonData, _ := json.Marshal(prj)
req, err := http.NewRequest("POST",
fmt.Sprintf("%s/%s/repos", CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetCreateCmd().Organisation),
fmt.Sprintf("%s/%s/repos", CfgGlobal.GetUrlApiOrgs(), CfgGlobal.GetCreateCmd().Organization),
bytes.NewBuffer(jsonData))
req.Header.Set("Authorization", "token "+CfgGlobal.GetGitTeaTokenEnv())
req.Header.Set("Content-Type", "application/json")
@ -89,22 +150,6 @@ func CreateProject(cmd *cobra.Command, args []string) error {
defer res.Body.Close()
// Create directory of the project
fmt.Println("==> Creating directory...")
utils.CreateDir(name)
fmt.Println("==> Created directory")
// Change to project directory
err = os.Chdir(name)
if err != nil {
log.Fatal(err)
}
isCreated := CreateReadme(name, description, "BC", "")
if isCreated {
fmt.Println("==> Created README.md")
}
// Git commands
gitCmd := exec.Command("git", "init")
err = gitCmd.Run()
@ -144,4 +189,7 @@ func CreateProject(cmd *cobra.Command, args []string) error {
fmt.Println(project)
return nil
}
func CreateGithubProject() {}

View File

@ -6,7 +6,7 @@ category:
software:
Go Lang:
name: "Go Lang"
version: "1.17.5"
version: "1.19.5"
author: "Google"
location: 'C:\Users\bruno\scoop\apps\go\current'
description: "Go is an open source programming language that makes it easy to build simple, reliable, and efficient software."
@ -26,11 +26,9 @@ category:
path:
- src/config
- src/version
test:
path:
- test
release:
path:
- release
@ -42,6 +40,15 @@ category:
# test: "go test"
# lint: "golint"
install apps:
Tasks:
name: "Tasks"
cmdWin: "scoop install tasks"
cmdLinux: "sudo apt-get install tasks"
Go:
cmd:
Win: "scoop install go"
Linux: "sudo apt-get install go"
Java:
software:
Quarkus:

View File

@ -44,9 +44,15 @@ type ListCmdConfig struct {
type CreateCmdConfig struct {
Name string
Organisation string
Description string
Private bool
DirectoryFlag bool
VersionFlag bool
ReadmeFlag bool
GitFlag bool
TeaFlag bool
Organization string
OrganizationFlag bool
PrivateFlag bool
}
type EnvCmdConfig struct {
@ -323,14 +329,84 @@ func (c *Config) SetCreateDescription(value string) {
c.CreateCmd.Description = value
}
// Getter for Directory field
func (c *Config) GetCreateDirectoryFlag() bool {
return c.CreateCmd.DirectoryFlag
}
// Setter for Directory field
func (c *Config) SetCreateDirectoryFlag(value bool) {
c.CreateCmd.DirectoryFlag = value
}
// Getter for versionFlag field
func (c *Config) GetCreateVersionFlag() bool {
return c.CreateCmd.VersionFlag
}
// Setter for versionFlag field
func (c *Config) SetCreateVersionFlag(value bool) {
c.CreateCmd.VersionFlag = value
}
// Getter for createReadme field
func (c *Config) GetCreateReadmeFlag() bool {
return c.CreateCmd.ReadmeFlag
}
// Setter for createReadme field
func (c *Config) SetCreateReadmeFlag(value bool) {
c.CreateCmd.ReadmeFlag = value
}
// Getter for createGit flag
func (c *Config) GetCreateGitFlag() bool {
return c.CreateCmd.GitFlag
}
// Setter for createGit flag
func (c *Config) SetCreateGitFlag(value bool) {
c.CreateCmd.GitFlag = value
}
// Getter for createTea flag
func (c *Config) GetCreateTeaFlag() bool {
return c.CreateCmd.TeaFlag
}
// Setter for createTea flag
func (c *Config) SetCreateTeaFlag(value bool) {
c.CreateCmd.TeaFlag = value
}
// Getter for create Orgenization field
func (c *Config) GetCreateOrgenization() string {
return c.CreateCmd.Organization
}
// Setter for create Orgenization field
func (c *Config) SetCreateOrgenization(value string) {
c.CreateCmd.Organization = value
}
// Getter for create Orgenization flag
func (c *Config) GetCreateOrgenizationFlag() bool {
return c.CreateCmd.OrganizationFlag
}
// Setter for create Orgenization flag
func (c *Config) SetCreateOrgenizationFlag(value bool) {
c.CreateCmd.OrganizationFlag = value
}
// Getter for createPrivate field
func (c *Config) GetCreatePrivate() bool {
return c.CreateCmd.Private
func (c *Config) GetCreatePrivateFlag() bool {
return c.CreateCmd.PrivateFlag
}
// Setter for createPrivate field
func (c *Config) SetCreatePrivate(value bool) {
c.CreateCmd.Private = value
func (c *Config) SetCreatePrivateFlag(value bool) {
c.CreateCmd.PrivateFlag = value
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -566,32 +642,56 @@ func (c *Config) InitCmdCreate(cmd *cobra.Command, args []string) {
// validate flag on create command
if cmd.Name() == "create" {
// set organization flag if set
if cmd.Flags().Changed("org") || cmd.Flags().Changed("o") {
c.SetListOrganization(cmd.Flag("org").Value.String())
c.SetListOrganizationFlag(true)
}
// set name flag if set
if cmd.Flags().Changed("name") || cmd.Flags().Changed("n") {
c.SetCreateName(cmd.Flag("name").Value.String())
}
// set description flag if set
if cmd.Flags().Changed("desc") || cmd.Flags().Changed("d") {
c.SetCreateDescription(cmd.Flag("desc").Value.String())
if cmd.Flags().Changed("description") || cmd.Flags().Changed("d") {
c.SetCreateDescription(cmd.Flag("description").Value.String())
}
// set Directory flag if set for create directories structure
if cmd.Flags().Changed("struc") || cmd.Flags().Changed("s") {
c.SetCreateDirectoryFlag(true)
// set version flag if set for adding verion control
if cmd.Flags().Changed("version") || cmd.Flags().Changed("v") {
c.SetCreateVersionFlag(true)
}
// set Readme flag if set for adding readme file
if cmd.Flags().Changed("readme") || cmd.Flags().Changed("r") {
c.SetCreateReadmeFlag(true)
}
}
// if Git flag or Tea flag is set
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") || cmd.Flags().Changed("tea") || cmd.Flags().Changed("t") {
// set private flag if set
if cmd.Flags().Changed("private") || cmd.Flags().Changed("p") {
if cmd.Flag("private").Value.String() == "true" {
c.SetCreatePrivate(true)
} else if cmd.Flag("private").Value.String() == "false" {
c.SetCreatePrivate(false)
} else {
c.SetCreatePrivate(false)
c.SetCreatePrivateFlag(true)
}
// set organization flag if set
if cmd.Flags().Changed("org") || cmd.Flags().Changed("o") {
c.SetCreateOrgenization(cmd.Flag("org").Value.String())
c.SetCreateOrgenizationFlag(true)
}
// set Git flag if set for creating git repository
if cmd.Flags().Changed("git") || cmd.Flags().Changed("g") {
c.SetCreateGitFlag(true)
} else if cmd.Flags().Changed("tea") || cmd.Flags().Changed("t") {
c.SetCreateTeaFlag(true)
}
}
}
}
@ -698,12 +798,17 @@ func (c *Config) printAllConfiguration() {
fmt.Println("Create commands Configuration:")
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("config: CreateName: ", c.GetCreateCmd().Name)
fmt.Println("config: Organization: ", c.GetCreateCmd().Organisation)
fmt.Println("config: CreateDescription: ", c.GetCreateCmd().Description)
fmt.Println("config: CreatePrivate: ", c.GetCreatePrivate())
fmt.Println("config: CreateCmd: ", c.GetCreateCmd())
fmt.Println("config: CreateName: ", c.GetCreateCmd().Name)
fmt.Println("config: CreateDescription: ", c.GetCreateDescription())
fmt.Println("config: CreateDirectory: ", c.GetCreateDirectoryFlag())
fmt.Println("config: VersionFlag", c.GetCreateVersionFlag())
fmt.Println("config: ReadMeFlag ", c.GetCreateReadmeFlag())
fmt.Println("config: GitFlag ", c.GetCreateGitFlag())
fmt.Println("config: TeaFlag ", c.GetCreateTeaFlag())
fmt.Println("config: Organization: ", c.GetCreateOrgenization())
fmt.Println("config: OrganizationFlag: ", c.GetCreateOrgenizationFlag())
fmt.Println("config: CreatePrivate: ", c.GetCreatePrivateFlag())
fmt.Println("Environment Variables Configuration:")
fmt.Println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
fmt.Println("config: EnvCmd: ", c.GetEnvCmd())

View File

@ -16,6 +16,7 @@ type SectionConfig struct {
EnvironmentsVariables map[string]string `yaml:"environments variables"`
Directory map[string]DirectoryConfig `yaml:"directory"`
Pipelines map[string]PipelineConfig `yaml:"pipelines"`
InstallApps map[string]InstallAppsConfig `yaml:"install apps"`
}
type SoftwareConfig struct {
@ -44,6 +45,12 @@ type PipelineConfig struct {
Lint string `yaml:"lint"`
}
type InstallAppsConfig struct {
Name string `yaml:"name"`
CmdWin string `yaml:"cmdWin"`
CmdLinux string `yaml:"cmdLinux"`
}
// function GetPathsFromCategory
func (c *ConfigYml) GetPathsFromCategory(sectionName string) ([]string, error) {
section, ok := c.Sections[sectionName]

View File

@ -31,6 +31,7 @@ func init() {
CfgGlobal.Init()
// root menu section
// - - - - - - - - - - -
rootCmd.Flags().BoolP("help", "h", false, "Show help for "+CfgGlobal.GetApplicationName())
rootCmd.Flags().BoolVarP(&CfgGlobal.VersionFlag, "version", "V", false, "Show VERSION of "+CfgGlobal.GetApplicationName())
rootCmd.CompletionOptions.DisableDefaultCmd = true
@ -38,20 +39,31 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&CfgGlobal.JsonFlag, "json", "j", false, "JSON output format")
// List menu section
// - - - - - - - - - - -
cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.TokenEnv, "token", "t", "", "TOKEN for Gitea or Github")
cmdLists.ListCmd.Flags().BoolVarP(&CfgGlobal.ListCmd.GitFlag, "git", "g", false, "List all repositories from GITHUB")
cmdLists.ListCmd.Flags().BoolVarP(&CfgGlobal.ListCmd.TeaFlag, "tea", "a", false, "List all repositories from GITEA")
cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.ListCmd.User, "user", "u", "", "user for request on GITHUB or GITEA")
cmdLists.ListCmd.Flags().StringVarP(&CfgGlobal.ListCmd.Organization, "org", "o", "", "List projects from an ORGANIZATION")
// Create menu section
cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.TokenEnv, "token", "t", "", "TOKEN for Gitea or Github")
cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Organisation, "org", "o", "", "ORGANIZATION for this project")
// Create menu section (create project directories structure, init git, Github or Gitea repository, create README.md template )
// - - - - - - - - - - - - - - - - - - -
// project informations
cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Name, "name", "n", "", "NAME of the Project")
cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Description, "desc", "d", "", "DESCRIPTION of the project")
cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.Private, "private", "p", false, "PRIVATE with this switch")
// project directories
cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.DirectoryFlag, "struc", "s", false, "Create project STRUCTURE")
// Project version
cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.VersionFlag, "Control", "c", false, "Add version CONTROL to the project")
// Project ReadMe
cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.ReadmeFlag, "readme", "r", false, "Add ReadMe.md to the project")
// Github or Gitea informations
cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.TokenEnv, "token", "t", "", "TOKEN for Gitea or Github")
cmdCreate.CreateCmd.Flags().StringVarP(&CfgGlobal.CreateCmd.Organization, "org", "o", "", "ORGANIZATION for this project")
cmdCreate.CreateCmd.Flags().BoolVarP(&CfgGlobal.CreateCmd.PrivateFlag, "private", "p", false, "PRIVATE with this switch")
// Env menu section
// - - - - - - - - - - -
cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesFlag, "group", "g", false, "GROUP environnement variables by categories")
cmdEnv.EnvCmd.Flags().BoolVarP(&CfgGlobal.EnvCmd.EnvVariablesListFlag, "list", "l", false, "LIST environnement variables")
cmdEnv.EnvCmd.Flags().StringVarP(&CfgGlobal.EnvCmd.EnvVariablesFilter, "filter", "f", "", "HIGHLIGHT a specific word in environnement variables")

View File

@ -1,18 +1,14 @@
# Project Creator
This is a simple CLI app to help you to do smalls things like :
- Look organizations and projects on Github and Gitea.
- Create a startup project structure base on a configuration file
- Create and push your projects into Github or Gitea.
- Look and manange environnement variable
-
Kode-Creator is a simple command-line interface (CLI) application designed to help developers get up and running quickly with some small tools for managing Github, software, environment variables, and more. The application is built using Go lang, which provides a simple, fast, and fun way to build your projects.
## Description
The **Kode-Creator** app allows you to:
- Create a Github project (repo)
- Initialize a Git repository
- Look organizations and projects on Github and Gitea.
- Create a startup project structure base on a configuration file
- Create and push your projects into Github or Gitea.
- Look and manange environnement variable
- Create an initial commit
- Generate a README.md file

View File

@ -15,7 +15,7 @@ type Version struct {
// version variable that will be set at build time by versionManager.exe
// *** DO NOT EDIT ***
var versionNumber Version = Version{0, 0, 0, 33}
var versionNumber Version = Version{0, 0, 0, 41}
// GetFullVersion returns the full version number as a string
func GetFullVersion() string {