autocomplete icon indicating copy to clipboard operation
autocomplete copied to clipboard

feat(typeorm): make spec diff-versioned

Open fedeci opened this issue 3 years ago • 6 comments

fedeci avatar Oct 01 '22 17:10 fedeci

Overview

src/typeorm/0.2.0.ts:

Info:

src/typeorm/index.ts:

Info:

src/typeorm/0.3.0.ts:

Info:

withfig-bot avatar Oct 01 '22 17:10 withfig-bot

Hello @fedeci, thank you very much for creating a Pull Request! Here is a small checklist to get this PR merged as quickly as possible:

  • [ ] Do all subcommands / options which take arguments include the args property (args: {})?
  • [ ] Are all options modular? E.g. -a -u -x instead of -aux
  • [ ] Have all other checks passed?

Please add a 👍 as a reaction to this comment to show that you read this.

withfig-bot avatar Oct 01 '22 17:10 withfig-bot

This makes it really verbose by duplicating the spec, but at the same time we should start to expand and to try to make as many open source projects as possible to be directly integrated with autocomplete!

fedeci avatar Oct 01 '22 17:10 fedeci

Closes #1158

fedeci avatar Oct 01 '22 17:10 fedeci

This makes it really verbose by duplicating the spec

I agree with you, I thought of this when I added autocomplete to pnpm.

I have an idea, maybe we should add a dependsOnVersion for subcommand

interface Subcommand {
	dependsOnVersion: (string | (executeShellCommand) => boolean)[]
}

When it's a string, you can refer directly to the package.json version control, which is a very mature solution.

Version range Matching version
* You can use subcommand regardless of the version, and this will be the default
^2.1.0 2.1.0 <= v < 3 Versions available
~2.1.0 2.1.0 <= v < 2.2 Versions available
2.1.0 - 3.2.7 2.1.0 <= v <= 3.2.7 Versions available
<2.2.0 ...
<=2.0.0 ...
\>4.2.0 ...
\>=4.2.0 ...
=4.3.0 ...
^0.7 || ~2 ...

When it's a function, we need to take into account that some commands depend not only on their own version but also on the version of the external environment, e.g. pnpm v7 requires nodejs >= 14, at which point we can do some custom comparisons in the function and return whether the version is available in the current environment.

eg:

{
// pnpm v7 
// pnpm patch
const completionSpec: Fig.Spec = {
	name: "pnpm",
	description: "Fast, disk space efficient package manager",
	args: {
    	name: "Scripts",
    	filterStrategy: "fuzzy",
    	generators: npmScriptsGenerator,
    	isVariadic: true,
  	},
	dependsOnVersion: [async ( executeShellCommand ){
			const nodeVersion = await executeShellCommand('node -v');
			return compareVersions(nodeVersion,'>=14')
		}],	// Maybe there are multiple environmental dependencies?

	subcommand:[
	{
    	name: "patch",
    	description: `This command will cause a package to be extracted in a temporary directory intended to be editable at will`,
		dependsOnVersion: '\>=7.14.0',
    	args: {
      		name: "package",
    	},
    	options: [
      	{
        	name: "--edit-dir",
        	description: `The package that needs to be patched will be extracted to this directory`,
      },
    ],
  },

}
]
}
  

loosheng avatar Dec 17 '22 16:12 loosheng

Hey @loosheng, we already have something like for subcommands this and it is called generateSpec. However since these solutions are really difficult to automate (they use functions to determine CLI tool version) we created diff-versioned specs like this one.

fedeci avatar Dec 18 '22 15:12 fedeci