Skip to content

Add ability to setup basepath via --basepath / -d in CLI - #496

Merged
samsonasik merged 3 commits into
0.19.xfrom
allow-define-basepath
Oct 8, 2026
Merged

samsonasik merged 3 commits into
0.19.xfrom
allow-define-basepath

Conversation

@samsonasik

Copy link
Copy Markdown
Member

Per @gsteel at

This PR adds ability to setup base path via --basepath in cli, eg:

analyze --basepath=../../

that mean, if we have project directory, eg:

src/
test
composer.json
├── tools
│   ├── structarmed
│   │   ├── composer.json
│   │   ├── composer.lock
│   │   ├── structarmed.php
│   │   └── vendor

and then, I want to run

cd tools/structarmed
vendor/bin/structarmed analyze --basepath=../../

eg, when the rule is instanceof ComposerJsonRuleInterface, it will scan ../../composer.json then by definiton of autoload/autoload-dev, it can read defined ../../composer.json definition, eg: src under autoload, and test under autoload in ../../composer.json

This also ensure, eg layer:

    ->layer('Config', 'src/ConfigProvider.php')
    ->layer('Exception', 'src/Exception')

that src/ConfigProvider.php is ../../src/ConfigProvider as new basepath is ../../ per cli command.

@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@samsonasik

Copy link
Copy Markdown
Member Author

@gsteel the new feature ready :), tested and verified on laminas-i18n repo:

Screenshot 2026-10-07 at 20 12 27

I will merge it tomorrow and then create StructArmed 0.19.0 release, just let me know if there is something you concern ;)

/cc @froschdesign

@gsteel

gsteel commented Oct 7, 2026

Copy link
Copy Markdown

I think it's more common to consider this a "Working Directory", i.e. where you do the work.

A common switch is -d like composer install -d ./somewhere-else with the assumption that the current working directory is . when unspecified.

So, if I run tools/structarmed/vendor/bin/structarmed --config=tools/structarmed/structarmed.php, I'd expect it to figure out that composer should be at ${PWD}/composer.json.

On the other hand, if I cd to the tools dir, I'd expect:

cd tools/structarmed
vendor/bin/structarmed -d ../../

to do the same thing, i.e. detect config in either CWD, or Working Dir and composer.json in working dir.

Hope I'm making sense!

@samsonasik

Copy link
Copy Markdown
Member Author

@gsteel The direct run from root already read root as expected, see this screenshot:

Screenshot 2026-10-07 at 20 32 16

and also I add the -d alias for --basepath: eb1c5f8

Should be ready now 👍

@samsonasik samsonasik changed the title Add ability to setup basepath via --basepath in CLI Add ability to setup basepath via --basepath / -d in CLI Oct 7, 2026
@gsteel

gsteel commented Oct 7, 2026

Copy link
Copy Markdown

Nice! Thanks @samsonasik - I should have read the initial patch more thoroughly!

@samsonasik
samsonasik merged commit 5bcc237 into 0.19.x Oct 8, 2026
14 checks passed
@samsonasik
samsonasik deleted the allow-define-basepath branch October 8, 2026 05:27
@samsonasik

Copy link
Copy Markdown
Member Author

Thank you @gsteel @froschdesign for the review.

It just merged and released 0.19.0 for it https://github.com/boundwize/structarmed/releases/tag/0.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants