Skip to content

Commit

Permalink
added version flag in create cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
vineshtk committed Oct 25, 2024
1 parent 3ca5357 commit 1524f79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 10 additions & 3 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,22 @@ and usage of using your command.`,
fmt.Println("Error retrieving domain flag:", err)
os.Exit(1)
}

version, err := cmd.Flags().GetString("version")
if err != nil {
fmt.Println("Error retrieving domain flag:", err)
os.Exit(1)
}

menu.ShowMainMenu()
menu.GetInputsFromUser(channelName)
menu.GetInputsFromUser(channelName, version)
},
}

func init() {

rootCmd.AddCommand(networkCmd)
// networkCmd.Flags().BoolVarP(&option, "option", "o", false, "Modify option")
networkCmd.Flags().String("channel", "", "for custom channel")

networkCmd.Flags().String("channel", "", "for custom channel(eg.mychannel)")
networkCmd.Flags().String("version", "2.5.4", "for specific fabric version(eg.2.5.4)")
}
12 changes: 6 additions & 6 deletions pkg/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ var keys []string
//go:embed defaults/peercfg/core.yaml
var coreYaml []byte

func CreateConfigs(domainName string, orgPeers map[string]int, channelName string) {
func CreateConfigs(domainName string, orgPeers map[string]int, channelName string, version string) {
CreateFolders(domainName)
CreateDockerComposeCA(domainName, orgPeers)
CreateDockerComposeMembers(domainName, orgPeers)
CreateDockerComposeMembers(domainName, orgPeers, version)
CreateConfigTx(domainName, orgPeers)
createPeercfg(domainName)
CreateRegisterEnroll(domainName, orgPeers)
Expand Down Expand Up @@ -221,7 +221,7 @@ func CreateDockerComposeCA(domainName string, orgPeers map[string]int) {
fmt.Println("docker-compose-ca.yaml Configuration file created/updated successfully!")
}

func CreateDockerComposeMembers(domainName string, orgPeers map[string]int) {
func CreateDockerComposeMembers(domainName string, orgPeers map[string]int, version string) {

//viper.KeyDelimiter(":") to adjust the key delimiter from "." to ":"
// for adding keys like "orderer.example.com"
Expand All @@ -240,7 +240,7 @@ func CreateDockerComposeMembers(domainName string, orgPeers map[string]int) {
// creating configs for ordering service
custom_viper.Set(fmt.Sprintf("volumes:orderer.%v", domainName), map[string]string{})
custom_viper.Set(fmt.Sprintf("services:orderer.%v:container_name", domainName), fmt.Sprintf("orderer.%v", domainName))
custom_viper.Set(fmt.Sprintf("services:orderer.%v:image", domainName), "hyperledger/fabric-orderer:2.5.4")
custom_viper.Set(fmt.Sprintf("services:orderer.%v:image", domainName),fmt.Sprintf( "hyperledger/fabric-orderer:%s", version))
custom_viper.Set(fmt.Sprintf("services:orderer.%v:labels:service", domainName), "hyperledger-fabric")

ordererEnv := []string{
Expand Down Expand Up @@ -305,7 +305,7 @@ func CreateDockerComposeMembers(domainName string, orgPeers map[string]int) {

// configs for CLI
custom_viper.Set("services:cli:container_name", "cli")
custom_viper.Set("services:cli:image", "hyperledger/fabric-tools:2.5.4")
custom_viper.Set("services:cli:image",fmt.Sprintf("hyperledger/fabric-tools:%s", version) )
custom_viper.Set("services:cli:labels:service", "hyperledger-fabric")
custom_viper.Set("services:cli:tty", true)
custom_viper.Set("services:cli:stdin_open", true)
Expand Down Expand Up @@ -368,7 +368,7 @@ func CreateDockerComposeMembers(domainName string, orgPeers map[string]int) {

// peer config
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:container_name", peer, org, domainName), fmt.Sprintf("peer%v.%v.%v", peer, org, domainName))
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:image", peer, org, domainName), "hyperledger/fabric-peer:2.5.4")
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:image", peer, org, domainName), fmt.Sprintf("hyperledger/fabric-peer:%s", version) )
custom_viper.Set(fmt.Sprintf("services:peer%v.%v.%v:labels:service", peer, org, domainName), "hyperledger-fabric")

peerEnv := []string{
Expand Down
4 changes: 2 additions & 2 deletions pkg/menu/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var domainName string

// var channelName string

func GetInputsFromUser(channelName string) {
func GetInputsFromUser(channelName string, version string) {
fmt.Print("\n")
fmt.Print("Enter the domain name (eg: example.com): ")
fmt.Scan(&domainName)
Expand Down Expand Up @@ -48,7 +48,7 @@ func GetInputsFromUser(channelName string) {
fmt.Scan(&channelName)
}

configs.CreateConfigs(domainName, OrganizationPeers, channelName)
configs.CreateConfigs(domainName, OrganizationPeers, channelName, version)

}

Expand Down

0 comments on commit 1524f79

Please sign in to comment.