cmd

package
v0.0.0-...-618aa7f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Copyright © 2024 NAME HERE <EMAIL ADDRESS>

Index

Constants

This section is empty.

Variables

View Source
var AdditionCmd = &cobra.Command{
	Use:   "Addition",
	Short: "Performs the addition operation for two numbers",
	Long:  ` Performs the addition operation for two numbers.`,
	Run: func(cmd *cobra.Command, args []string) {

		fmt.Println("Addition called")

		if len(args) != 2 {
			fmt.Println("Error: Please provide two numbers")
		}

		var a, b int
		var err error

		a, err = strconv.Atoi(args[0])
		if err != nil {
			fmt.Println("Error: Invalid input for the first number.")
			return
		}

		b, err = strconv.Atoi(args[1])
		if err != nil {
			fmt.Println("Error: Invalid input for the second number.")
			return
		}

		result := a + b
		fmt.Printf("The result is %d\n", result)

	},
}

AdditionCmd represents the Addition command

View Source
var DivisionCmd = &cobra.Command{
	Use:   "Division",
	Short: "Performs the division operation for two numbers",
	Long:  "Performs the division operation for two numbers.",

	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Division called")
		var a, b int
		var err error

		if len(args) != 2 {
			fmt.Println("Error : Please provide two numbers ")
		}

		a, err = strconv.Atoi(args[0])
		if err != nil {
			fmt.Println("Error : Invalid input for the first number. ")
			return
		}

		b, err = strconv.Atoi(args[1])
		if err != nil {
			fmt.Println("Error : Invalid input for the second number. ")
		}

		result := a / b
		fmt.Printf("The result is %d\n", result)
	},
}

DivisionCmd represents the Division command

View Source
var MultiplicationCmd = &cobra.Command{
	Use:   "Multiplication",
	Short: "Performs the multiplication operation for two numbers",
	Long:  "Performs the multiplication operation for two numbers.",

	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Multiplication called")

		var a, b int
		var err error

		if len(args) != 2 {
			fmt.Println("Error : Please provide two numbers ")
		}

		a, err = strconv.Atoi(args[0])
		if err != nil {
			fmt.Println("Error : Invalid input for the first number. ")
			return
		}

		b, err = strconv.Atoi(args[1])
		if err != nil {
			fmt.Println("Error : Invalid input for the second number. ")
		}

		result := a * b
		fmt.Printf("The result is %d\n", result)

	},
}

MultiplicationCmd represents the Multiplication command

View Source
var SubtractionCmd = &cobra.Command{
	Use:   "Subtraction",
	Short: "Performs the subtraction operation for two numbers",
	Long:  "Performs the subtraction operation for two numbers.",

	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Subtraction called")

		var a, b int
		var err error

		if len(args) != 2 {
			fmt.Println("Error : Please provide two numbers ")
		}

		a, err = strconv.Atoi(args[0])
		if err != nil {
			fmt.Println("Error : Invalid input for the first number. ")
			return
		}

		b, err = strconv.Atoi(args[1])
		if err != nil {
			fmt.Println("Error : Invalid input for the second number. ")
		}

		result := a / b
		fmt.Printf("The result is %d\n", result)
	},
}

SubtractionCmd represents the Subtraction command

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL