MCPcopy Index your code
hub / github.com/coder/coder / PrintDeprecatedOptions

Function PrintDeprecatedOptions

cli/root.go:1749–1793  ·  view source on GitHub ↗

PrintDeprecatedOptions loops through all command options, and prints a warning for usage of deprecated options.

()

Source from the content-addressed store, hash-verified

1747// PrintDeprecatedOptions loops through all command options, and
1748// prints a warning for usage of deprecated options.
1749func PrintDeprecatedOptions() serpent.MiddlewareFunc {
1750 return func(next serpent.HandlerFunc) serpent.HandlerFunc {
1751 return func(inv *serpent.Invocation) error {
1752 opts := inv.Command.Options
1753 // Print deprecation warnings.
1754 for _, opt := range opts {
1755 if opt.UseInstead == nil {
1756 continue
1757 }
1758
1759 if opt.ValueSource == serpent.ValueSourceNone || opt.ValueSource == serpent.ValueSourceDefault {
1760 continue
1761 }
1762
1763 // Verify that this deprecated option was itself
1764 // the source of the value. Serpent propagates
1765 // ValueSource across all options that share the
1766 // same Value pointer, so a new option being set
1767 // can make a deprecated sibling appear set when
1768 // it was not.
1769 source := deprecatedOptionDirectSource(inv, opt)
1770 if source == serpent.ValueSourceNone {
1771 continue
1772 }
1773
1774 var warnStr strings.Builder
1775 _, _ = warnStr.WriteString(translateSource(source, opt))
1776 _, _ = warnStr.WriteString(" is deprecated, please use ")
1777 for i, use := range opt.UseInstead {
1778 _, _ = warnStr.WriteString(translateSource(source, use))
1779 if i != len(opt.UseInstead)-1 {
1780 _, _ = warnStr.WriteString(" and ")
1781 }
1782 }
1783 _, _ = warnStr.WriteString(" instead.\n")
1784
1785 cliui.Warn(inv.Stderr,
1786 warnStr.String(),
1787 )
1788 }
1789
1790 return next(inv)
1791 }
1792 }
1793}
1794
1795// deprecatedOptionDirectSource returns the source by which a deprecated
1796// option was directly set, ignoring any propagated ValueSource from

Callers 2

CommandMethod · 0.85

Calls 5

WarnFunction · 0.92
translateSourceFunction · 0.85
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by 1