-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2785 from ipfs/feature/auto-synopsis
Add synopsis autogenerator
- Loading branch information
Showing
15 changed files
with
124 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cli | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
cmds "github.com/ipfs/go-ipfs/commands" | ||
) | ||
|
||
func TestSynopsisGenerator(t *testing.T) { | ||
command := &cmds.Command{ | ||
Arguments: []cmds.Argument{ | ||
cmds.StringArg("required", true, false, ""), | ||
cmds.StringArg("variadic", false, true, ""), | ||
}, | ||
Options: []cmds.Option{ | ||
cmds.StringOption("opt", "o", "Option"), | ||
}, | ||
Helptext: cmds.HelpText{ | ||
SynopsisOptionsValues: map[string]string{ | ||
"opt": "OPTION", | ||
}, | ||
}, | ||
} | ||
syn := generateSynopsis(command, "cmd") | ||
t.Logf("Synopsis is: %s", syn) | ||
if !strings.HasPrefix(syn, "cmd ") { | ||
t.Fatal("Synopsis should start with command name") | ||
} | ||
if !strings.Contains(syn, "[--opt=<OPTION> | -o]") { | ||
t.Fatal("Synopsis should contain option descriptor") | ||
} | ||
if !strings.Contains(syn, "<required>") { | ||
t.Fatal("Synopsis should contain required argument") | ||
} | ||
if !strings.Contains(syn, "<variadic>...") { | ||
t.Fatal("Synopsis should contain variadic argument") | ||
} | ||
if !strings.Contains(syn, "[<variadic>...]") { | ||
t.Fatal("Synopsis should contain optional argument") | ||
} | ||
if !strings.Contains(syn, "[--]") { | ||
t.Fatal("Synopsis should contain options finalizer") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters