onepub-dev / dcli

An extensive library and tooling for building console/cli applications and scripts using the Dart programming language.
245 stars 26 forks source link

Getting the path of the dcli script #186

Closed cedvdb closed 2 years ago

cedvdb commented 2 years ago

I would like to be able to run this package https://pub.dev/packages/flutter_launcher_icons#book-guide from a dcli script.

The command provided with this package lets you parametrize the path of the configuration file like so:

flutter pub run flutter_launcher_icons:main -f <your config file name here>

The issue I have is that I'd like to have a premade configuration file provided by the script but it is a bit unclear how to get the path of said configuration file. I'm unsure how to get that path, especially since the script could be run directly eg: my_cli or via pub dart run my_cli. So using which does not seem to be an option.

Here is an example folder structure:

  - bin
     my_cli.dart
  - configs
     launcher_icons_config.yaml

Is there a way to get that configuration file path ?

bsutton commented 2 years ago

join(DartProject.self.projectRoot, 'configs)

On Fri, 11 Feb 2022, 9:29 pm cedvdb, @.***> wrote:

I would like to be able to run this package https://pub.dev/packages/flutter_launcher_icons#book-guide from a dcli script.

The command provided with this package lets you parametrize the path of the configuration file like so:

flutter pub run flutter_launcher_icons:main -f

The issue I have is that I'd like to have a premade configuration file provided by the script but it is a bit unclear how to get the path of said configuration file. I'm unsure how to get that path, especially since the script could be run directly eg: my_cli or via pub dart run my_cli`.

Here is an example folder structure:

  • bin my_cli.dart
  • configs launcher_icons_config.yaml

Is there a way to get that configuration file path ?

— Reply to this email directly, view it on GitHub https://github.com/noojee/dcli/issues/186, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OGJH56VZWA5ZCSYARDU2TQKHANCNFSM5OD2BHRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

cedvdb commented 2 years ago

It seems that pathToProjectRoot gives the project I've installed the cli app into. In my case it's path/to/example_app_using_my_cli. What I was after was the path of the dependency path/to/my_cli. However I can find another way to resolve this.

bsutton commented 2 years ago

The path to the script is

DartScript.self.pathTo???

On Sat, 12 Feb 2022, 3:55 am cedvdb, @.***> wrote:

It seems that pathToProjectRoot gives the project I've installed the cli app into. However I can find another way to resolve this.

— Reply to this email directly, view it on GitHub https://github.com/noojee/dcli/issues/186#issuecomment-1036413058, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAG32OFWV56DTASWQ5EC4ULU2U5PZANCNFSM5OD2BHRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

cedvdb commented 2 years ago

I'm not sure why you gave this type of answer, is it because it is seemingly obvious ?

Anyway of all the methods available on self, none provide what I'm after, that is I tried:

  print(DartScript.self.pathToExe);
  print(DartScript.self.pathToInstalledExe);
  print(DartProject.self.pathToBinDir);
  print(DartProject.self.pathToDartToolDir);
  print(DartProject.self.pathToProjectRoot);
  print(DartProject.self.pathToTestDir);
  print(DartProject.self.pathToToolDir);
  print(DartProject.self.pathTo???!!!????!);

That being said, I found a better workaround. Still it could be a feature that could be added in the library or maybe not, you be the judge to which extent this could be useful.

I'm leaving this open since the feature apparently do not exists.

bsutton commented 2 years ago

So I'm a little unclear on what your structure is.

If you intend running the my_cli tool from the my_cli package directory then the DartProject idea should work as it will return the root of the my_cli package.

What I was after was the path of the dependency

So my_cli being used in a separate package.

It sounds like there are three things. flutter_launcher_icons:main the my_cli tool some package you want to run my_cli on: some_package

If thats the case you should complie my_cli

dcli compile --install my_cli

cd some_package // run the my_cli command my_cli

The my_cli command can then use 'pwd' (a dcli global function) to obtain the directory you are working in or better DartProject.fromPath(pathTo: pwd).pathToProjectRoot

This will give you the root of the some_package project provided your current directory is somewhere in that package.

cedvdb commented 2 years ago

I'm wasting both of us time here, first because I failed to express clearly what I was after secondly because I found a better alternative which does not require me to find that path which should be found regardless of how the my_cli is installed. Therefor I'm closing this.

Also I wanna give you props for the awesome documentation, especially on the history nutshell side of linux, very interesting.