Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize scripts in src dir in subdirectories #398

Closed
n-rodriguez opened this issue Jul 3, 2023 · 8 comments
Closed

Organize scripts in src dir in subdirectories #398

n-rodriguez opened this issue Jul 3, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@n-rodriguez
Copy link

Description

Hi there!

Today scripts are organized in srcdir in a flat way :

src/
├── bashly.yml
├── completions_command.sh
├── concerto_config_dump_command.sh
├── concerto_config_print_command.sh
├── concerto_notify_release_command.sh
├── concerto_notify_sentry_command.sh
├── concerto_restart_command.sh
├── concerto_setup_command.sh
├── concerto_update_french_logo_command.sh
├── concerto_update_staging_command.sh
├── docker_config_command.sh
├── docker_down_command.sh
├── docker_enter_command.sh
├── docker_exec_command.sh
├── docker_images_command.sh
├── docker_logs_command.sh
├── docker_prune_images_command.sh
├── docker_ps_command.sh
├── docker_pull_command.sh
├── docker_restart_command.sh
├── docker_start_command.sh
├── docker_stop_command.sh
├── docker_top_command.sh
├── docker_up_command.sh
├── get_config_concerto_version_command.sh
├── get_config_date_command.sh
├── get_config_debian_version_command.sh
├── get_config_env_command.sh
├── get_config_local_command.sh
├── get_config_service_version_command.sh
├── lib
│   ├── colors.sh

It would be great to have an option to organize scripts in subdirectories :

src/
├── bashly.yml
├── completions_command.sh
├── concerto
│   └── config_dump_command.sh
│   └── config_print_command.sh
│   └── notify_release_command.sh
│   └── notify_sentry_command.sh
│   └── restart_command.sh
│   └── setup_command.sh
│   └── update_french_logo_command.sh
│   └── update_staging_command.sh
├── docker
│   └── start_command.sh
│   └── config_command.sh
│   └── down_command.sh
│   └── enter_command.sh
│   └── exec_command.sh
│   └── images_command.sh
│   └── logs_command.sh
│   └── prune_images_command.sh
│   └── ps_command.sh
│   └── pull_command.sh
│   └── restart_command.sh
│   └── start_command.sh
│   └── stop_command.sh
│   └── top_command.sh
│   └── up_command.sh

Thank you!

@n-rodriguez n-rodriguez added the enhancement New feature or request label Jul 3, 2023
@DannyBen
Copy link
Owner

DannyBen commented Jul 3, 2023

Well - it is nice to see that bashly is easy enough to use that you have built (or planning to build) such a large bash script with it.

There is a command.filename option which lets you specify the path (in src) for each command. Isn't this sufficient?

See:


But now that I look a all this, I agree - it is tedious, and I am not a big fan of the fact that so many filenames end with *_command.sh.

I am going to try to do the following:

Have a setting in the settings.yml to say something like command_paths: nested that will set the path of a command docker status to src/commands/docker/status.sh instead of src/docker_status_command.sh

Makes sense?

@n-rodriguez
Copy link
Author

Have a setting in the settings.yml to say something like command_paths: nested that will set the path of a command docker status to src/commands/docker/status.sh instead of src/docker_status_command.sh

Makes sense?

Sure!

But I don't know how your last PR will solve this issue? #399

@DannyBen
Copy link
Owner

DannyBen commented Jul 3, 2023

The PR adds a setting value, that when set, will automatically organize all the commands in the src folder, in subdirectories.

See this example.

Points of interest:

# The path to use for command files, relative to source_dir
# When set to nil (~), command files will be placed directly under source_dir
# When set to any other string, command files will be placed under this
# directory, and each command will get its own subdirectory
# commands_dir: ~
commands_dir: commands

https://github.com/DannyBen/bashly/tree/master/examples/command-paths/src/commands

And, if you have sub-sub-commands - like cli docker image ls, its file will be src/commands/docker/image/ls.sh

Meaning: The setting not only sets a sub directory for commands, but it also changes the entire path generation logic.

Isn't this what you wanted?

You can use the edge version to test it.

@n-rodriguez
Copy link
Author

You can use the edge version to test it.

I did with

# frozen_string_literal: true

source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }

gem 'bashly', github: 'DannyBen/bashly'

It works :)

├── commands
│   ├── completions.sh
│   ├── concerto
│   │   ├── config_dump.sh
│   │   ├── config_print.sh
│   │   ├── notify_release.sh
│   │   ├── notify_sentry.sh
│   │   ├── restart.sh
│   │   ├── setup.sh
│   │   ├── update_french_logo.sh
│   │   └── update_staging.sh
│   ├── docker
│   │   ├── config.sh
│   │   ├── down.sh
│   │   ├── enter.sh
│   │   ├── exec.sh
│   │   ├── images.sh
│   │   ├── logs.sh
│   │   ├── prune_images.sh
│   │   ├── ps.sh
│   │   ├── pull.sh
│   │   ├── restart.sh
│   │   ├── start.sh
│   │   ├── stop.sh
│   │   ├── top.sh
│   │   └── up.sh
│   ├── get-config
│   │   ├── concerto-version.sh
│   │   ├── date.sh
│   │   ├── debian-version.sh
│   │   ├── env.sh
│   │   ├── local.sh
│   │   └── service-version.sh
│   ├── maintenance
│   │   ├── start.sh
│   │   ├── status.sh
│   │   └── stop.sh
│   ├── postgres
│   │   ├── backup.sh
│   │   ├── psql.sh
│   │   ├── reindex.sh
│   │   ├── restore.sh
│   │   └── vacuum.sh
│   ├── rails
│   │   ├── console.sh
│   │   └── rake.sh
│   └── redis
│       └── cli.sh

At first I was surprised by the commands dir but it's consistent with the lib dir sitting next to it.

Thank you! It works great!

@DannyBen
Copy link
Owner

DannyBen commented Jul 3, 2023

It is beautiful right? Much better for large scripts.

Thanks for suggesting it. I am updating the example so it is clearer that commands get subdirectories as well.

@n-rodriguez
Copy link
Author

It is beautiful right?

It is 👍 ❤️

@DannyBen
Copy link
Owner

DannyBen commented Jul 7, 2023

Released in 1.0.7
Docs: https://bashly.dannyb.co/usage/settings/#commands_dir

This was a nice one Nicolas, thanks.

@iamjackg
Copy link

We've indeed been doing this manually the whole time for our (also pretty large) script :) Thanks for adding this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants