Skip to content

Commit

Permalink
feat: create 'list_objects()'
Browse files Browse the repository at this point in the history
  • Loading branch information
morteza-jamali committed Oct 8, 2021
1 parent 3bc0275 commit 5ddfed3
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
.history
.ionide

# Test files
tmp

# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
50 changes: 25 additions & 25 deletions bin/rbsh.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#!/bin/bash

# Init constants
BACKUP_DIR_NAME=".rbsh"
META_FILE_NAME=".rbsh_meta"
BACKUP_DIR_PATH="$HOME/$BACKUP_DIR_NAME"
META_FILE_PATH="$HOME/$META_FILE_NAME"

# Remove source objects (files, directories, etc.)
remove() {
# $1 is source object

this_time=$(($(date +%s%N)/1000000))
obj_backup_dir_name="$(echo $this_time)_$(basename $1)"
obj_backup_dir_path="$BACKUP_DIR_PATH/$obj_backup_dir_name/"
source_obj=$1

if [ -d $1 ]; then
source_obj="$source_obj/"
fi

mkdir "$obj_backup_dir_path" && \
mv "$source_obj" "$obj_backup_dir_path" && \
add_meta $obj_backup_dir_name
}

clear() {}

add_meta() {
echo "$1" >> "$META_FILE_PATH"
}

remove $1
# CLI options
HELP_OPTION_LONG="--help"
HELP_OPTION_SHORT="-h"
LIST_ARGUMENT="list"

# Load core functions
source ./source/core.sh

# Check options and arguments
while [ "$#" -gt 0 ]; do
case "${1^^}" in
"${LIST_ARGUMENT^^}")
list_objects
shift
;;
"${HELP_OPTION_LONG^^}" | "${HELP_OPTION_SHORT^^}")
show_help
shift
;;
*)
shift
;;
esac
done
9 changes: 9 additions & 0 deletions scripts/file_mock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

TMP_DIR_PATH="./tmp"

rm -rf $TMP_DIR_PATH

mkdir -p $TMP_DIR_PATH/test1/test1_sub1
touch $TMP_DIR_PATH/test1/apple.js
touch $TMP_DIR_PATH/test1/test1_sub1/test1_sub1_apple.ts
37 changes: 37 additions & 0 deletions source/core.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Remove source objects (files, directories, etc.)
remove() {
# $1 is source object

this_time=$(($(date +%s%N)/1000000))
obj_backup_dir_name="$(echo $this_time)_$(basename $1)"
obj_backup_dir_path="$BACKUP_DIR_PATH/$obj_backup_dir_name/"
source_obj=$1

if [ -d $1 ]; then
source_obj="$source_obj/"
fi

mkdir "$obj_backup_dir_path" && \
mv "$source_obj" "$obj_backup_dir_path" && \
add_meta $obj_backup_dir_name $(realpath $1)
}

# Add metadata to rbsh meta file
add_meta() {
# $1 is backup file path
# $2 is source absolute path

echo "$1, $2" >> "$META_FILE_PATH"
}

# List all removed objects
list_objects() {
ls -la $BACKUP_DIR_PATH
}

# Show cli help
show_help() {
rm --help
}
28 changes: 14 additions & 14 deletions spec/spec_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
# set -eu

# This callback function will be invoked only once before loading specfiles.
spec_helper_precheck() {
# Available functions: info, warn, error, abort, setenv, unsetenv
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION
: minimum_version "0.28.1"
}
# spec_helper_precheck() {
# # Available functions: info, warn, error, abort, setenv, unsetenv
# # Available variables: VERSION, SHELL_TYPE, SHELL_VERSION
# : minimum_version "0.28.1"
# }

# This callback function will be invoked after a specfile has been loaded.
spec_helper_loaded() {
:
}
# # This callback function will be invoked after a specfile has been loaded.
# spec_helper_loaded() {
# :
# }

# This callback function will be invoked after core modules has been loaded.
spec_helper_configure() {
# Available functions: import, before_each, after_each, before_all, after_all
: import 'support/custom_matcher'
}
# # This callback function will be invoked after core modules has been loaded.
# spec_helper_configure() {
# # Available functions: import, before_each, after_each, before_all, after_all
# : import 'support/custom_matcher'
# }
8 changes: 8 additions & 0 deletions spec/test_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Describe 'sample'
Describe 'implemented by shell function'
Include ./scripts/file_mock.sh

It 'performs addition'
End
End
End

0 comments on commit 5ddfed3

Please sign in to comment.