Repository: DiceDB/dice
File: internal/eval/commands.go (Go)

Code before:
	DiceCmds["RENAME"] = renameCmdMeta
	DiceCmds["GETEX"] = getexCmdMeta
	DiceCmds["PTTL"] = pttlCmdMeta
	DiceCmds["HSET"] = hsetCmdMeta
	DiceCmds["OBJECT"] = objectCmdMeta
	DiceCmds["TOUCH"] = touchCmdMeta
	DiceCmds["LPUSH"] = lpushCmdMeta
	DiceCmds["RPOP"] = rpopCmdMeta
	DiceCmds["RPUSH"] = rpushCmdMeta
	DiceCmds["LPOP"] = lpopCmdMeta
	DiceCmds["DBSIZE"] = dbSizeCmdMeta
	DiceCmds["GETSET"] = getSetCmdMeta
	DiceCmds["FLUSHDB"] = flushdbCmdMeta
	DiceCmds["BITPOS"] = bitposCmdMeta
	DiceCmds["SADD"] = saddCmdMeta
	DiceCmds["SMEMBERS"] = smembersCmdMeta
	DiceCmds["SREM"] = sremCmdMeta
	DiceCmds["SCARD"] = scardCmdMeta
	DiceCmds["SDIFF"] = sdiffCmdMeta
	DiceCmds["SINTER"] = sinterCmdMeta
	DiceCmds["HGETALL"] = hgetAllCmdMeta
	DiceCmds["PFADD"] = pfAddCmdMeta
	DiceCmds["PFCOUNT"] = pfCountCmdMeta
}

func convertKeySpecsToSlice(keySpecs KeySpecs) []interface{} {
	return []interface{}{
		"BeginIndex", keySpecs.BeginIndex,
		"LastKey", keySpecs.LastKey,
		"Step", keySpecs.Step,
	}
}

// Function to convert DiceCmdMeta to []interface{}
func convertCmdMetaToSlice(cmdMeta DiceCmdMeta) []interface{} {
	keySpecsSlice := convertKeySpecsToSlice(cmdMeta.KeySpecs)
	return []interface{}{cmdMeta.Name, cmdMeta.Arity, keySpecsSlice}
}

// Function to convert map[string]DiceCmdMeta{} to []interface{}
func convertDiceCmdsMapToSlice() []interface{} {
	var result []interface{}
	for _, cmdMeta := range DiceCmds {
		result = append(result, convertCmdMetaToSlice(cmdMeta))
	}
	return result
}


Review comment (security):
Shall we keep parity with redis output? For `COMMAND` e.g. our output for `HELLO`
```
0.0.0.0:7379> command
 1) 1) "HELLO"
    2) (integer) -1
    3) 1) "BeginIndex"
       2) (integer) 0
       3) "LastKey"
       4) (integer) 0
       5) "Step"
       6) (integer) 0
```
Redis output:
```
205) 1) "hello"
     2) (integer) -1
     3) 1) "noscript"
        2) "loading"
        3) "stale"
        4) "fast"
        5) "no_auth"
        6) "allow_busy"
     4) (integer) 0
     5) (integer) 0
     6) (integer) 0
     7) 1) "@fast"
        2) "@connection"
     8) (empty array)
     9) (empty array)
     10) (empty array)
```
Redis output follows below format:

1. Name
2. Arity
3. Flags
4. First key
5. Last key
6. Step
7. [ACL categories](https://redis.io/operate/oss_and_stack/management/security/acl) (as of Redis 6.0)
8. [Tips](https://redis.io/develop/reference/command-tips.md) (as of Redis 7.0)
9. [Key specifications](https://redis.io/develop/reference/key-specs.md) (as of Redis 7.0)
10. Subcommands (as of Redis 7.0)

We don't have all the fields set but for the ones we do have available we should maintain parity.
More details you can found [here](https://redis.io/docs/latest/commands/command/).

Code after:
	DiceCmds["RENAME"] = renameCmdMeta
	DiceCmds["GETEX"] = getexCmdMeta
	DiceCmds["PTTL"] = pttlCmdMeta
	DiceCmds["HSET"] = hsetCmdMeta
	DiceCmds["OBJECT"] = objectCmdMeta
	DiceCmds["TOUCH"] = touchCmdMeta
	DiceCmds["LPUSH"] = lpushCmdMeta
	DiceCmds["RPOP"] = rpopCmdMeta
	DiceCmds["RPUSH"] = rpushCmdMeta
	DiceCmds["LPOP"] = lpopCmdMeta
	DiceCmds["DBSIZE"] = dbSizeCmdMeta
	DiceCmds["GETSET"] = getSetCmdMeta
	DiceCmds["FLUSHDB"] = flushdbCmdMeta
	DiceCmds["BITPOS"] = bitposCmdMeta
	DiceCmds["SADD"] = saddCmdMeta
	DiceCmds["SMEMBERS"] = smembersCmdMeta
	DiceCmds["SREM"] = sremCmdMeta
	DiceCmds["SCARD"] = scardCmdMeta
	DiceCmds["SDIFF"] = sdiffCmdMeta
	DiceCmds["SINTER"] = sinterCmdMeta
	DiceCmds["HGETALL"] = hgetAllCmdMeta
	DiceCmds["PFADD"] = pfAddCmdMeta
	DiceCmds["PFCOUNT"] = pfCountCmdMeta
}

// Function to convert DiceCmdMeta to []interface{}
func convertCmdMetaToSlice(cmdMeta DiceCmdMeta) []interface{} {
	return []interface{}{cmdMeta.Name, cmdMeta.Arity, cmdMeta.KeySpecs.BeginIndex, cmdMeta.KeySpecs.LastKey, cmdMeta.KeySpecs.Step}
}

// Function to convert map[string]DiceCmdMeta{} to []interface{}
func convertDiceCmdsMapToSlice() []interface{} {
	var result []interface{}
	for _, cmdMeta := range DiceCmds {
		result = append(result, convertCmdMetaToSlice(cmdMeta))
	}
	return result
}