Skip to content

Commit

Permalink
Shell: added Is_Command_* functions suite
Browse files Browse the repository at this point in the history
Since the Is_Command_* functions suite was accidentally ported,
it's better to commit it in. Hence, let's do this.

This patch adds Is_Command_* functions suite into Shell/
directory.

Co-authored-by: Shuralyov, Jean <[email protected]>
Co-authored-by: Galyna, Cory <[email protected]>
Co-authored-by: (Holloway) Chew, Kean Ho <[email protected]>
Signed-off-by: (Holloway) Chew, Kean Ho <[email protected]>
  • Loading branch information
3 people committed Dec 26, 2024
1 parent 540d996 commit 59663f8
Show file tree
Hide file tree
Showing 40 changed files with 2,530 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Alias.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Errors\Error_Codes.ps1"




function HestiaKERNEL-Is-Command-Alias-OS {
param (
[string]$___command
)


# validate input
if ($___command -eq "") {
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}


# execute
$___process = Get-Command $___command `
-CommandType Alias `
-ErrorAction SilentlyContinue
if ($___process) {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Alias.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"




HestiaKERNEL_Is_Command_Alias_OS() {
#___command="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
fi


# execute
___ret="$(type "$1")"
if [ ! "${___ret##*alias}" = "$___ret" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
}
37 changes: 37 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Available.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Errors\Error_Codes.ps1"




function HestiaKERNEL-Is-Command-Available-OS {
param (
[string]$___command
)


# validate input
if ($___command -eq "") {
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}


# execute
$___process = Get-Command $___command -ErrorAction SilentlyContinue
if ($___process) {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Available.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"




HestiaKERNEL_Is_Command_Available_OS() {
#___command="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
fi


# execute
___ret="$(type "$1")"
if [ "${___ret##*not found}" = "$___ret" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
}
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Builtin.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Errors\Error_Codes.ps1"




function HestiaKERNEL-Is-Command-Builtin-OS {
param (
[string]$___command
)


# validate input
if ($___command -eq "") {
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}


# execute
$___process = Get-Command $___command `
-CommandType Cmdlet `
-ErrorAction SilentlyContinue
if ($___process) {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Builtin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"




HestiaKERNEL_Is_Command_Builtin_OS() {
#___command="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
fi


# execute
___ret="$(type "$1")"
if [ ! "${___ret##*shell builtin}" = "$___ret" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
}
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_External.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Errors\Error_Codes.ps1"




function HestiaKERNEL-Is-Command-External-OS {
param (
[string]$___command
)


# validate input
if ($___command -eq "") {
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}


# execute
$___process = Get-Command $___command `
-CommandType Application, ExternalScript, Script `
-ErrorAction SilentlyContinue
if ($___process) {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}
45 changes: 45 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_External.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${LIBS_HESTIA}/HestiaKERNEL/Errors/Error_Codes.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/OS/Is_Command_Alias.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/OS/Is_Command_Available.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/OS/Is_Command_Builtin.sh"
. "${LIBS_HESTIA}/HestiaKERNEL/OS/Is_Command_Function.sh"




HestiaKERNEL_Is_Command_External_OS() {
#___command="$1"


# validate input
if [ "$1" = "" ]; then
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
fi


# execute
if [ "$(HestiaKERNEL_Is_Command_Alias_OS "$1")" -ne $HestiaKERNEL_ERROR_OK ] &&
[ "$(HestiaKERNEL_Is_Command_Builtin_OS "$1")" -ne $HestiaKERNEL_ERROR_OK ] &&
[ "$(HestiaKERNEL_Is_Command_Function_OS "$1")" -ne $HestiaKERNEL_ERROR_OK ] &&
[ "$(HestiaKERNEL_Is_Command_Available_OS "$1")" -eq $HestiaKERNEL_ERROR_OK ]; then
printf -- "%d" $HestiaKERNEL_ERROR_OK
return $HestiaKERNEL_ERROR_OK
fi


# report status
printf -- "%d" $HestiaKERNEL_ERROR_DATA_MISSING
return $HestiaKERNEL_ERROR_DATA_MISSING
}
39 changes: 39 additions & 0 deletions Shell/libraries/HestiaKERNEL/OS/Is_Command_Function.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2024 (Holloway) Chew, Kean Ho <[email protected]>
#
#
# Licensed under (Holloway) Chew, Kean Ho’s Liberal License (the "License").
# You must comply with the license to use the content. Get the License at:
#
# https://doi.org/10.5281/zenodo.13770769
#
# You MUST ensure any interaction with the content STRICTLY COMPLIES with
# the permissions and limitations set forth in the license.
. "${env:LIBS_HESTIA}\HestiaKERNEL\Errors\Error_Codes.ps1"




function HestiaKERNEL-Is-Command-Function-OS {
param (
[string]$___command
)


# validate input
if ($___command -eq "") {
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}


# execute
$___process = Get-Command $___command `
-CommandType Function `
-ErrorAction SilentlyContinue
if ($___process) {
return ${env:HestiaKERNEL_ERROR_OK}
}


# report status
return ${env:HestiaKERNEL_ERROR_DATA_MISSING}
}
Loading

0 comments on commit 59663f8

Please sign in to comment.